2

Ok, I hate to start another of seemingly hundreds of other threads about this, but how do I set or tweak the PYTHONPATH? I'm very new to Mac and the only other time I've successfully done this was on Windows using Rapid Enviroment Editor. This looks like a whole different beast. I tried installing Django and it failed to do it for 2.7, while I need 3.4, so the current path must be for 2.7. Running which python in Terminal shows the /usr/bin/python directory, which I then can't cd into, let alone find by browsing. I see that my Python 3.4 directory has the Update Shell Profile file, but it has a lot of limitations. I also see other threads mention PYTHONPATH commands in IDLE and creating one of the bash profile type files for the Terminal. How can I set this and not worry about it anymore until I need to run a different version of Python? I'm on Mac 10.9.2. "Explain like I'm five".

4
  • Try typing python3 (or python3.4) instead of python. You shouldn't need to set PYTHONPATH at all; it does not control which version of the Python interpreter you are using. Likewise, use pip3 (or pip34) to install Django and friends. Commented Jun 17, 2014 at 18:28
  • how did you try installing django? Commented Jun 17, 2014 at 18:32
  • @PadraicCunningham pip install Django==1.6.5 Commented Jun 17, 2014 at 18:41
  • @sivanes, I added an answer. There are different pip's for python2.7 and 3.4. You need to specify pip3 or maybe pip3.4 when you want to install a package for python 3.4 Commented Jun 17, 2014 at 18:43

2 Answers 2

5

If you want to install packages for python 3.4 use: pip3 install django

When installing for python 2.7 just use: pip install django

To use python 3.4 type python3 in your shell.

To see where all installations of python are use: which -a python

Depending on how you installed the new versions of python you will see output like:

/usr/local/bin/python
/usr/bin/python

If you wanted to use the python in /usr/local/bin/python you can edit your .bashrc file and add export path="/usr/local/bin:$path".

Save, then type source .bashrc in your shell and when you type which python it will show something like /usr/local/bin/python

Don't screw around too much with different versions of python, you will end up causing yourself a lot of problems. You should not have to change your PYTHONPATH, just specify which python or pip version you want to use and that will most likely be all you need to do.

Sign up to request clarification or add additional context in comments.

5 Comments

Isn't PYTHONPATH the most sure fire way to exclude confusions between installed versions when it comes to interpreting? At least, that's what I remember about running Python scripts in Windows. Also, I did which -a python3 and got /Library/Frameworks/Python.framework/Versions/3.4/bin/python3 /usr/local/bin/python3 is the /usr/~ shorthand for /Library/~ or why does it give two paths?
The output is just an example, it is os dependant. what does which python3 output? Windows and unix are very different.
Ah ok, the /Library/etc path. Thank you for the explanations!
No worries, if you have any other questions feel free to ask.
@sivanes, On OS X using the python.org installers, /usr/local/bin/python3.4 is indeed a shortcut for /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 and, if python3.4 is the most recently installed version of python3, so is /usr/local/bin/python3. By default, the python.org installers try to add /Library/Frameworks/Python.framework/Versions/3.4/bin to your shell PATH environment variable which determines which directories are searched for command line executables, like python3. PYTHONPATH augments Python's sys.path, the search path for imports.
1

To update PYTHONPATH you can run from the terminal:

    export PYTHONPATH=$PYTHONPATH:/desired/path/to/add

Then to check the updated PYTHONPATH you can run:

    echo $PYTHONPATH

I'm not sure if this completely answers your question, but this is one way to make sure modules are visible to python when you import them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.