Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the PYTHONPATH in shell?

debian@debian:~$ echo $PYTHONPATH   /home/qiime/lib/:   debian@debian:~$ python   Python 2.7.3 (default, Jan  2 2013, 16:53:07)    [GCC 4.7.2] on linux2   Type "help", "copyright", "credits" or "license" for more information.   >>> import sys   >>> sys.path   ['', '/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', '/usr/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', '/usr/lib/python2.7/dist-packages/gst-0.10',   '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7']     

How can I get all of PYTHONPATH output in bash?
Why echo $PYTHONPATH can not get all of them?

like image 538
showkey Avatar asked Apr 29 '13 01:04

showkey


People also ask

How do I find my Pythonpath?

Use sys. path for that. By simple experiment, I found Vanuan's answer below (printing sys. path) just prints PYTHONPATH.

What is the Pythonpath?

PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.


1 Answers

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
like image 130
Hubro Avatar answered Sep 23 '22 10:09

Hubro