Python Library Path

Python

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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')

Solution 2 - Python

I think you're looking for sys.path

import sys
print (sys.path)

Solution 3 - Python

import sys
sys.path

Solution 4 - Python

python -c "import sys; print('\n'.join(sys.path))"


/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python39.zip
/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9
/usr/local/Cellar/[email protected]/3.9.10/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload
/usr/local/lib/python3.9/site-packages

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyle BurtonView Question on Stackoverflow
Solution 1 - PythonapgView Answer on Stackoverflow
Solution 2 - PythonJack M.View Answer on Stackoverflow
Solution 3 - PythonJohn MillikinView Answer on Stackoverflow
Solution 4 - PythonCodeFarmerView Answer on Stackoverflow