题记
在之前的文章centos云服务器安装Python3记录 记录了怎么自定义安装 Python3 ,在后边测试pip3的时候发现了个问题:
pip --version
terminal 打印:
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
如上:pip版本还是 Python2.7 版本
解决
由于对于系统和Python并不是特别熟悉,首先想到的是问下度娘。度娘给了几种建议全部是下载pip再安装。我没有急于执行而是去看了下 官方文档
其中有这样的表述:
大概意思是:
1.看下系统内pip是否可用:
[[email protected] python3]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
2.查看pip是否存在于安装包
[[email protected] python3]# python -m ensurepip --default-pip
Looking in links: /tmp/tmpzzl1ppca
Requirement already satisfied: setuptools in ./lib/python3.7/site-packages (39.0.1)
Requirement already satisfied: pip in ./lib/python3.7/site-packages (10.0.1)
3. 由步骤 2 可知,pip3已经存在于 Python3.7 的安装文件中,只是没有对应的软链
[[email protected] bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[[email protected] bin]# pip3 --version
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
4.想起来自己mac上的pip还是用的pip3,于是也修改软链。
Last login: Sat Sep 29 23:13:21 on ttys002
liuyonghudeMacBook-Pro:~ liuyonghu$ pip3 --version
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)
liuyonghudeMacBook-Pro:~ liuyonghu$ which python3
/usr/local/bin/python3
liuyonghudeMacBook-Pro:~ liuyonghu$ which pip3
/usr/local/bin/pip3
liuyonghudeMacBook-Pro:~ liuyonghu$ ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 /usr/local/bin/pip
liuyonghudeMacBook-Pro:~ liuyonghu$ pip --version
pip 9.0.1 from /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)
5. 其实中间查找pip路径的步骤比较费劲,也记录下来。
[[email protected] python3]# pip --version
pip 8.1.2 from /usr/lib/python2.7/site-packages (python 2.7)
[[email protected] python3]# python -m ensurepip --default-pip
Looking in links: /tmp/tmpzzl1ppca
Requirement already satisfied: setuptools in ./lib/python3.7/site-packages (39.0.1)
Requirement already satisfied: pip in ./lib/python3.7/site-packages (10.0.1)
[[email protected] python3]# cd /user/bin
-bash: cd: /user/bin: 没有那个文件或目录
[[email protected] python3]# cd /usr/bin
[[email protected] bin]# ls pip*
pip pip2 pip2.7
[[email protected] bin]# mv pip pip.bak
[[email protected] bin]# cd ./lib/python3.7/site-packages (10.0.1)
-bash: 未预期的符号 `(' 附近有语法错误
[[email protected] bin]# cd usr/lib/python3.7/site-packages (10.0.1)
-bash: 未预期的符号 `(' 附近有语法错误
[[email protected] bin]# cd usr/lib/python3.7/site-packages
-bash: cd: usr/lib/python3.7/site-packages: 没有那个文件或目录
[[email protected] bin]# mv pip.bak pip
[[email protected] bin]# ls pip*
pip pip2 pip2.7
[[email protected] bin]# cd usr/lib/python3.7
-bash: cd: usr/lib/python3.7: 没有那个文件或目录
[[email protected] bin]# cd usr/local/python3
-bash: cd: usr/local/python3: 没有那个文件或目录
[[email protected] bin]# cd /usr/lib/python3.7
-bash: cd: /usr/lib/python3.7: 没有那个文件或目录
[[email protected] bin]# cd /usr/local
[[email protected] local]# cd python3
[[email protected] python3]# ls pip*
ls: 无法访问pip*: 没有那个文件或目录
[[email protected] python3]# ls
bin include lib share
[[email protected] python3]# cd lib
[[email protected] lib]# cd lib
-bash: cd: lib: 没有那个文件或目录
[[email protected] lib]# ls pip*
ls: 无法访问pip*: 没有那个文件或目录
[[email protected] lib]# cd ..
[[email protected] python3]# cd bin
[[email protected] bin]# ls pip*
pip3 pip3.7
[[email protected] bin]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[[email protected] bin]# pip3 --version
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
总结:
1.Python3 在解压,在预定目录,编译安装之后,生成了Python、pip的执行文件。
2.在系统中的指令存在于不同系统的 /usr/*/bin/ 文件夹中,如有需要可以自己去建立软链。
原文地址:https://www.cnblogs.com/tig666666/p/9733009.html
时间: 2024-10-17 08:33:33