如何在mac上为2.7设置python路径?
我知道,这个问题已被问及许多次。但是,我仍然无法摆脱这一点。我在我的Mac上发现了以下信息。如何在mac上为2.7设置python路径?
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.
即使这样,当我编辑~/.bash_profile
如下
# 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
然后,source ~/.bash-profile
。在重新启动我的终端后,仍然可以看到/usr/bin/python
而不是在执行which python
时指向/Library/../Python2.7
。
我卸载Python和重新安装"pip install python"
还有,我能看到下/System/Library/Frameworks/Python.framework/Versions
2.6
2.7
2.5 -> 2.6
2.3 -> 2.6
Current -> 2.7
Python安装我不知道有什么可以在这里失踪。我如何设置/添加mac中的python路径?请帮助我理解并克服这一点。你能帮我吗?
如果您已经安装在计算机上的Python的多个版本应该是在/ usr/bin中多个二进制文件为每一个
MacBook-Pro:~ ak47$ ls /usr/bin | grep python
> python
> python2.6
> python2.7
您可以通过更改访问每个不同的解释触发
“显式优于隐式”
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
另外,我强烈建议不要在使用多个版本的python时使用PYTHONPATH变量,因为python会为所有版本使用相同的变量。使用'sitecustomize.py'和'usercustomize.py'机制来操作'sys.path'。 – Gribouillis
通过brew安装。 brew install python2 or python3
。 brew会自动设置mac中的python路径。
事实上,如前所述,使用Brew安装最新版本的python可能是最好的处理方式,但请注意,从Python 2.7.13 Homebrew开始并不会将该版本的Python添加到您的自动路径。它警告你必须在你的.bash_profile中添加“export PATH =”/ usr/local/opt/python/libexec/bin:$ PATH“”。做到这一点,一切都会按预期工作。
为什么不使用类似pyenv的东西? – aristotll
类型python2.7;或'ls/usr/bin | grep python' – AK47