Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting up pythonpath in OS X

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?

like image 786
Jean-Luc Neptune Avatar asked Nov 02 '13 06:11

Jean-Luc Neptune


People also ask

How do I create a Pythonpath variable?

To set this variable from the Command Prompt, use: set PYTHONPATH=list;of;paths . To set this variable from PowerShell, use: $env:PYTHONPATH='list;of;paths' just before you launch Python.

What is PATH variable Mac?

PATH is an essential environment variable that decides how programs and commands work on macOS. Setting the PATH variable for a program or script allows you to run it from anywhere on the file system without specifying its absolute path.


2 Answers

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.

like image 94
synthesizerpatel Avatar answered Sep 19 '22 17:09

synthesizerpatel


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
like image 35
laalto Avatar answered Sep 21 '22 17:09

laalto