引言:
我15年的 Mac 自带python 2.7、现在18年python发展到了3.7
安装python后 自带包管理工具 pip【如果没有 偷懒的话 重新下载安装】
pip2 和 pip3 安装第三方库
重点 :pip后要加数字我觉得很不舒服
所以我打算建立一个软连接
最后希望实现的效果如下:
Jerry:~ Jerry$ pip --version
pip 18.0 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
首先安装默认的pip管理工具 注意:这个pip包管理工具是和 Mac系统python2.7相关联的。
Jerry:~ Jerry$ sudo easy_install pip
pip包安装后、查看pip包的版本状态,
Jerry:~ Jerry$ pip --version
pip 10.0 from /Users/Jerry/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
可知它还是老的pip版本,它的第三方库 是放在Python2.7下的 ../site-packages/pip
而我们经常会用到第三方的库,例如requests、requests_html,
如果使用 pip install xxx
将会造成问题
Jerry:~ Jerry$ pip install xxx
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/jdcal.py'
Consider using the `--user` option or check the permissions.
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
报错提示我们的 pip版本不对,需要更新pip
配置
Jerry:~ Jerry$ pip install --upgrade pip
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-10.0.1-py2.7.egg/EGG-INFO/PKG-INFO'
Consider using the `--user` option or check the permissions.
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
上面很遗憾又提示我们报错了 需要加 --user
Jerry:~ Jerry$ pip install --user --upgrade pip
Cache entry deserialization failed, entry ignored
Collecting pip
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 902kB/s
Installing collected packages: pip
Successfully installed pip-18.0
接下来我们 检查一下当前的 pip
版本
Jerry:~ Jerry$ pip --version
pip 18.0 from /Users/Jerry/Library/Python/2.7/lib/python/site-packages/pip (python 2.7)
这个时候大功告成、我们只是python2.7的环境 把 python包管理工具 pip 更新到了18.0
所以接下来我们安装python3.7
先安装python-3.7.0-macosx10.9.pkg包【里面自带pip3】安装包
查看Mac 自带python 的pip 包管理工具的启动路径
Jerry:~ Jerry$ which pip
/usr/local/bin/pip
/usr/local/bin/pip3
Jerry:~ Jerry$ pip3 --version
pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
Jerry:~ Jerry$ pip --version
pip 18.0 from /Library/Python/2.7/site-packages/pip-18.0-py2.7.egg/pip (python 2.7)
Jerry:~ Jerry$ rm -rf /usr/local/bin/pip3
Jerry:~ Jerry$ rm -rf /usr/local/bin/pip
Jerry:~ Jerry$ which pip3
/Library/Frameworks/Python.framework/Versions/3.7/bin/pip3
Jerry:~ Jerry$ ln -s /Library/Frameworks/Python.framework/Versions/3.7/bin/pip /usr/local/bin/pip
最后
Jerry:~ Jerry$ pip --version
pip 18.0 from /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pip (python 3.7)
总结:最新的Python版本 和 最新的包管理工具绑定成功 、其实就是把python2.7 默认的pip命令 指向了 python3.7的 pip相当于 pip 这个快捷方式指向了 pip3 这样下载第三方库 不在需要后面加个 pip2
pip3
这种数字了,因为我平时这两个版本不交互使用,【pip2 即系统默认的pip
】就这样修改了