问题
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
回答1:
If you have multiple versions of Python installed on your computer there should be multiple binaries in /usr/bin for each one
MacBook-Pro:~ ak47$ ls /usr/bin | grep python
> python
> python2.6
> python2.7
You can access each different interpreter by changing the trigger
"Explicit is better than implicit"
MacBook-Pro:~ ak47$ python --version
> Python 2.7.10
MacBook-Pro:~ ak47$ python2.6 --version
> Python 2.6.9
MacBook-Pro:~ ak47$ python2.7 --version
> Python 2.7.10
MacBook-Pro:~ ak47$ python3 --version
> Python 3.5.2
回答2:
Install via brew. brew install python2 or python3
.
brew sets the python path in mac automatically.
回答3:
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.
回答4:
From the current directory you want to add in your python path
export PYTHONPATH=$PYTHONPATH:`pwd`
来源:https://stackoverflow.com/questions/45649473/how-to-setup-python-path-for-2-7-on-mac