How to get the PYTHONPATH in shell?
Those of us using Python 3.x should do this:
python -c "import sys; print(sys.path)"
Just write:
just write which python
in your terminal and you will see the python path you are using.
Python, at startup, loads a bunch of values into sys.path
(which is "implemented" via a list of strings), including:
- various hardcoded places
- the value of
$PYTHONPATH
- probably some stuff from startup files (I'm not sure if Python has
rcfiles
)
$PYTHONPATH
is only one part of the eventual value of sys.path
.
If you're after the value of sys.path
, the best way would be to ask Python (thanks @Codemonkey):
python -c "import sys; print sys.path"
The environment variable PYTHONPATH
is actually only added to the list of locations Python searches for modules. You can print out the full list in the terminal like this:
python -c "import sys; print(sys.path)"
Or if want the output in the UNIX directory list style (separated by :
) you can do this:
python -c "import sys; print(':'.join(x for x in sys.path if x))"
Which will output something like this:
/usr/local/lib/python2.7/dist-packages/feedparser-5.1.3-py2.7.egg:/usr/local/lib/ python2.7/dist-packages/stripogram-1.5-py2.7.egg:/home/qiime/lib:/home/debian:/us r/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib /python2.7/lib-old:/usr/lib/python2.7/lib- dynload:/usr/local/lib/python2.7/dist- packages:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages/PIL:/u sr/lib/python2.7/dist-packages/gst-0.10:/usr/lib/python2.7/dist-packages/gtk-2.0: /usr/lib/pymodules/python2.7