了解python的安装路径,有利于处对python安装的管理。比如删除多余的python,可以在这些路径中查询处理。
一、Mac下python的安装路径
1、Mac自带python路径
/System/Library/Frameworks/Python.framework/Versions
对应系统 pip 安装的第三方库的安装路径:
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
2、Mac中自己安装的python3.x的路径
/Library/Frameworks/Python.framework/Versions/3.x
对应 pip 安装的第三方库的安装路径: ( 比如Django Flask 都是安装在这里 )
Library/Frameworks/Python.framework/Versions/3.x/lib/python3.x/site-packages
3、homebrew安装python路径
/usr/local/Cellar/python@2 //@2 表示python版本,也可以是 @3
homebrew 安装的外部包的安装路径:
/Library/Python
二、brew 安装指定版本 python3
1、安装
brew install python@3.8
2、错误处理
xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer)
原因:卸载了Xcode或者升级Xcode导致
处理:
sudo xcode-select -r sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools xcode-select -
3、查看安装路径
方法一:terminal
python3 >>> import sys >>> sys.path
打印结果:
['', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/lib-dynload', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages', '/Library/Python/3.8/site-packages', '/Library/Python/3.8/site-packages/Django-4.0.4-py3.8.egg']
方法二:terminal
which python3
方法三:mac版Pycharm第三方库路径
/Library/Python