How to setup python path for 2.7 on mac?

Viewed 34372

I am aware that, this question has been asked and answered many times. But, still i couldn't get rid of this. I found out the following info on my mac.

cd /Library/Frameworks/Python.framework/Versions/
Current -> 2.7
3.6

whereispython
/usr/bin/python

which python
/usr/bin/python

which -a python
/usr/bin/python
/usr/bin/python

python
Python 2.7.10 (default) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Even though, when i edit ~/.bash_profile as below

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

#PYTHONPATH
PYTHONPATH="${PYTHONPATH}:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python"
export PYTHONPATH

Then, source ~/.bash-profile. After restarting my mac & terminal, could see still /usr/bin/python instead of pointing to /Library/../Python2.7 when executed which python.

I uninstalled python and re-installed "pip install python" And also, i could see python installed under /System/Library/Frameworks/Python.framework/Versions

2.6
2.7
2.5 -> 2.6
2.3 -> 2.6
Current -> 2.7

I am not sure what could be missing here. How can i set/add the python path in mac ? Please help me to understand and overcome this. Can you please help me here ?

Reference Adding python path to mac osx

4 Answers

Install via brew. brew install python2 or python3. brew sets the python path in mac automatically.

Indeed, as mentioned, installing an up-to-date version of python using Brew is probably the best way to proceed, but be aware that starting with python 2.7.13 Homebrew doesn't add that version of python to your path automatically. It warns you that you must add "export PATH="/usr/local/opt/python/libexec/bin:$PATH"" to your .bash_profile. Do that and everything will work as expected.

From the current directory you want to add in your python path

export PYTHONPATH=$PYTHONPATH:`pwd`
Related