mac上Python安装和修改Python默认路径遇到的问题

2018-09-11  本文已影响311人  PC_Repair

此处例子是我使用homebrew安装了python3.6.1,建立一个符号链接,创建一个python3的命令,达到使用自己安装的python3的目的。此处不修改PATH,而是把需要添加的可执行文件或者符号链接放进PATH定义好的目录下(比如/usr/local/bin)。

Mac上Python环境位置:

1.Mac系统自带的python环境在:
Python 2.7.10:/System/Library/Frameworks/Python.framework/Version/2.7
其中,解释器在该目录下的 ./bin/python2.7
Python 2.6.9:/System/Library/Frameworks/Python.framework/Version/2.6
其中,解释器在该目录下的 ./bin/python2.6

2.用户安装的python环境默认环境在:
python 3.4.2:/Library/Frameworks/Python.framework/Version/3.4
其中,解释器在该目录下的 ./bin/python3.4
python 2.7.7:/Library/Frameworks/Python.framework/Version/2.7
其中,解释器在该目录下的 ./bin/python2.7

3.homebrew安装的python在
../Cellar/python3/3.6.1/bin
pip3所在位置:/Cellar/python3/3.6.1/bin/pip3

命令总结:
ls -al /usr/local/bin | grep python
image
../Cellar/python3/3.6.1/bin/python3
image
ls -l ../Cellar/python3/3.6.1/bin | grep python
image
ln -s ../Cellar/python3/3.6.1/bin/python3 /usr/local/bin/python3

若软链接已存在(删除原有链接再建立软链接):

rm /usr/local/bin/python3
#删除原有链接
ln -s ../Cellar/python3/3.6.1/bin/python3 /usr/local/bin/python3 

最终使用截图如下:

image
同理设置 python2 对应 ../Cellar/python/2.7.13/bin/python
ln -s ../Cellar/python/2.7.13/bin/python /usr/local/bin/python2

image
上一篇 下一篇

猜你喜欢

热点阅读