How to get current import paths in Python?

aligf picture aligf · Apr 22, 2011 · Viewed 58k times · Source

I get an ImportError exception somewhere in the code, but the same module can be imported safely at startup of the application. I'm curious to see which paths Python looks for modules to import, so that I can trace why this problem occurs. I found this:

print sys.path

Is this the list of ALL paths that system looks when tries to import a module?

Answer

Praveen Gollakota picture Praveen Gollakota · Apr 22, 2011

The path locations that python checks by default can be inspected by checking sys.path.

import sys
print(sys.path)