2

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

Alexander
  • 105,104
  • 32
  • 201
  • 196
Yeping Sun
  • 405
  • 1
  • 6
  • 18
  • If it's not defined, why are you trying to use it in the first line ? – Nir Alfasi Aug 19 '17 at 02:04
  • `{$PYTHONPATH}` is an error. That would result in an invalid path containing literal `{` and `}` characters. I think you mean `${PYTHONPATH}`. – larsks Aug 19 '17 at 02:15
  • But to you question: I cannot think of any way in which the two lines you have in your question would result in the behavior you are seeing (provided that these lines and your `echo` command all happen in the same shell). Are you sure the commands you are typing match exactly what you have posted here? What happens if you copy and paste? – larsks Aug 19 '17 at 02:16

2 Answers2

1

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 (i.e., with no intervening spaces) preceded by a colon.

See more here: Python - PYTHONPATH in linux

rndus2r
  • 496
  • 4
  • 17
1
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.

DUDANF
  • 2,618
  • 1
  • 12
  • 42