Python Library Path

Python Library Path

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?

2

4 Answers

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

I think you're looking for sys.path

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


/usr/local/Cellar/python@3.9/3.9.10/Frameworks/
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/
/usr/local/Cellar/python@3.9/3.9.10/Frameworks/
/usr/local/lib/python3.9/site-packages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.