7

A new PHP developer here trying to learn Python/Django using the "Tango With Django" tutorial.

I'm up to section 2.2.2 where I have to set up the pythonpath and I'm having the following problem:

When I type the following in the terminal: echo $pythonpath I get a blank line instead of the correct path.

I followed the troubleshooting steps and found where the site-packages directory is: Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

Per their instructions I updated my .bashrc file so it looks like this now:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
export PYTHONPATH=$PYTHONPATH:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

For a reason I don't understand I'm still getting a blank line when I echo $pythonpath.

Because I was having difficulty getting the pythonpath set up I skipped it, but then had problems installing Setuptools, Pip, and Django.

Can anyone tell me what I'm doing wrong? Any resources I can look at beside Tango with Django?

nickie
  • 5,608
  • 2
  • 23
  • 37
Jean-Luc Neptune
  • 93
  • 1
  • 2
  • 9
  • Try `set` rather than `echo $path`. This will list all environment variables available in the current shell. – fredrik Nov 02 '13 at 07:44

3 Answers3

6

2 issues I can see -

  1. $pythonpath and $PYTHONPATH are different. You want $PYTHONPATH. You will never use the lower-case version $pythonpath for anything, everything Python will 'respond' to will be in uppercase (by default)

  2. By default, $PYTHONPATH is empty and only necessary to add additional paths to beyond the defaults. To see the default list you can run this command in a shell:

    python -c 'import sys;print(sys.path)'
    

More than likely, the path you want will be in that list.

Thanks @martinanton for the python 3.0 update

synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91
  • Thanks for the quick response. I forgot to mention that I was aware of the issue of case sensitivity and had tested both upper and lower case versions of $PYTHONPATH/$pythonpath. Still getting a blank line when I try to echo the variable, but whatever I did to the path in the .bashrc file seems to work now and I was able to successfully install Pip and Setuptools. Appreciate your help! – Jean-Luc Neptune Nov 02 '13 at 16:05
  • 1
    Nowadays it should be ```import sys;print(sys.path)``` – martinanton Apr 28 '23 at 07:01
4

For a reason I don't understand I'm still getting a blank line when I echo $pythonpath.

Environment variables are case sensitive. PYTHONPATH and pythonpath are different. So:

echo $PYTHONPATH
laalto
  • 150,114
  • 66
  • 286
  • 303
  • 1
    Thanks for the quick response. I forgot to mention that I was aware of the issue of case sensitivity and had tested both upper and lower case versions of $PYTHONPATH/$pythonpath. Still getting a blank line when I try to echo the variable, but whatever I did to the path in the .bashrc file seems to work now and I was able to successfully install Pip and Setuptools. Appreciate your help! – Jean-Luc Neptune Nov 02 '13 at 16:04
1

First you should make sure that .bashrc is being executed when you open a new terminal screen.

If it doesn't, i recommend adding the following line to .bash_profile under your user home directory: [[ -s ~/.bashrc ]] && source ~/.bashrc

this line will make sure .bashrc exist, and if it does, it will execute it. As mentioned, both .bash_profile and .bashrc should be located under /Users//

Hope this helps. Meny

Meny Issakov
  • 1,400
  • 1
  • 14
  • 30