简体   繁体   中英

How to set PYTHONPATH in Centos 7?

In Centos 7 system, what is the default pythonpath enviroment? Before I make any pythonpath setting, the command "echo $PYTHONPATH" gives no output. After I make the following setting:

PYTHONPATH="{$PYTHONPATH}:/usr/lib/python2.7/site-packages:/usr/lib64/python2.7/site-packages/pandas:/app/anaconda2/pkgs"
export PYTHONPATH=$PYTHONPATH:/app/Jade

the command "echo $PYTHONPATH" gives the following output:

:/app/Jade

I don't understand why before "/app/Jade" there is an extra colon (:). And what is the correct way to set PYTHONPATH?

Best regards.

Yeping Sun

This has nothing to do with $PYTHONPATH but is a more generally PATH naming scheme. PATH is a colon-seperated list. From What is path?

Thus, for example, to add a directory named /usr/test to a user's PATH variable, it should be appended with a text editor to the line that begins with PATH so that the line reads something like PATH=$PATH:$HOME/bin:/usr/test . It is important that each absolute path be directly (ie, with no intervening spaces) preceded by a colon.

See more here: Python - PYTHONPATH in linux

export PYTHONPATH=/usr/lib/python2.7/site-packages:/usr/lib64/python2.7/site-packages/pandas:/app/anaconda2/pkgs:/app/Jade

The problem is in your first one, you included "" around $PYTHONPATH .

Secondly, the correct way to do this is:

export PATH=$PATH:/path/to/python

You can do which python to figure out what your path to Python is.

And then simply to export PYTHONPATH=/app/Jade <-- this may be incorrect as well since you need to supply this with an absolute path. Unless app is in your root folder, this won't work.

ALSO if you could copy-paste the exact error you are getting, that would be really helpful to the SO community in helping you, with this post and future posts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM