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".
2 Answers
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.
5 Comments
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?/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.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.
python3(orpython3.4) instead ofpython. You shouldn't need to setPYTHONPATHat all; it does not control which version of the Python interpreter you are using. Likewise, usepip3(orpip34) to install Django and friends.pip install Django==1.6.5