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

此处例子是我使用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

命令总结:
  • 显示/usr/local/bin目录下所有与"python"字符串相关的文件,查看python3指向的文件
ls -al /usr/local/bin | grep python
image
  • 此处运行 python3.6.1的一种方法如下,退出可用 exit()
../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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容