Python Library Path


Question

In ruby the library path is provided in $:, in perl it's in @INC - how do you get the list of paths that Python searches for modules when you do an import?

1
64
3/23/2017 6:28:36 PM

Accepted Answer

I think you're looking for sys.path

import sys
print (sys.path)
79
11/27/2014 6:35:32 AM

You can also make additions to this path with the PYTHONPATH environment variable at runtime, in addition to:

import sys
sys.path.append('/home/user/python-libs')

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon