87

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
  • 2
    In Ruby I think you meant $:. $" is a list of modules loaded by require. Commented Oct 9, 2011 at 16:57
  • 1
    You might want to take a look at my answer and others to this related question here: stackoverflow.com/a/38485710/436794 Commented Jan 10, 2018 at 16:43

5 Answers 5

120

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')
Sign up to request clarification or add additional context in comments.

Comments

102

I think you're looking for sys.path

import sys
print (sys.path)

Comments

12
import sys
sys.path

Comments

6
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

Comments

3

To get a good overview without even opening a python prompt you can use this:

python -m site

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.