Setting up pythonpath in OS X

14,780

Solution 1

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.

Solution 2

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

Solution 3

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

Share:
14,780
Jean-Luc Neptune
Author by

Jean-Luc Neptune

Updated on June 14, 2022

Comments

  • Jean-Luc Neptune
    Jean-Luc Neptune almost 2 years

    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?