Search code examples
shellpython-2.7zshzshrc

Export of PYTHONPATH from .zshrc not working


I'm trying to export the PYTHONPATH environment variable from my .zshrc, but fails.

relevant lines from .zshrc

PYTHONPATH="/Users/nicolas/Code:/Users/nicolas/Code/Dashboard"
export $PYTHONPATH

** from the command line **

1] test one

echo $PYTHONPATH
/Users/nicolas/Code:/Users/nicolas/Code/Dashboard

appears to work

2] test two

`sh -c 'echo "$PYTHONPATH"' `
==> empty output

actually doesnt

3] test three

running the folloing python script, with the command python script.py

#!/usr/bin/env python
import os
try:
    user_paths = os.environ['PYTHONPATH'].split(os.pathsep)
except KeyError:
    user_paths = 'no pythonpath'
print user_paths

outputs : no pythonpath

fails again

4] test four

zsh -x -c 'echo moo'

+/etc/zshenv:2> [ -x /usr/libexec/path_helper ']'
+/etc/zshenv:3> /usr/libexec/path_helper -s
+/etc/zshenv:3> eval 'PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/X11/bin:/usr/texbin:/Users/nicolas/anaconda/bin:/opt/local/lib/postgresql93/bin:/Users/nicolas/Code/games:/Users/nicolas/Code/Dashboard";' export 'PATH;'
+(eval):1> PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/X11/bin:/usr/texbin:/Users/nicolas/anaconda/bin:/opt/local/lib/postgresql93/bin:/Users/nicolas/Code/games:/Users/nicolas/Code/Dashboard
+(eval):1> export PATH
+zsh:1> echo moo
moo

extra info :

which zsh

outputs : /usr/local/bin/zsh

My $PATH is ok, it's perfectly similar from the terminal and from inside python.

What is happening, and how can i solve this ?

Using Mac os, python installed from anaconda


Solution

  • This export $PYTHONPATH is incorrect.

    export takes variable names not values.

    You want export PYTHONPATH.

    Your line is equivalent to export /Users/nicolas/Code:/Users/nicolas/Code/Dashboard which, as you might be able to tell, isn't very useful.