pip和pip3安装、升级、版本查看及遇到的问题

pip的安装

问题一

sudo apt-get install python-pip       #安装pip
sudo pip install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com             #换成阿里镜像,升级pip

然后查看版本时出现如下错误:

rogn@ubuntu:~$ pip -V
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main

据说原因是:pip 10.0.0及以上版本没有main()

方法一

考虑降个版本,10.0.0一下就行,例如:

python -m pip install --upgrade pip==9.0.3

以后不要随便升级。

方法二

这篇博客中说,只需修改 /usr/bin/pip 文件:

这里一定要记得加sudo,也就是以管理员身份打开,否则没有权限修改

from pip import main
if __name__ == '__main__':
    sys.exit(main())

改成:

from pip import __main__
if __name__ == '__main__':
    sys.exit(__main__._main())

此时查看版本:

rogn@ubuntu:~$ pip -V
/home/rogn/.local/lib/python2.7/site-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
pip 19.0.3 from /home/rogn/.local/lib/python2.7/site-packages/pip (python 2.7)

发现已经是19.0.3,问题解决!

 

问题二

一下是作死过程,请自行忽略

仔细看前面pip -V查看版本时有警告,即:

rogn@ubuntu:~$ pip -V
/home/rogn/.local/lib/python2.7/site-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
pip 19.0.3 from /home/rogn/.local/lib/python2.7/site-packages/pip (python 2.7)

这篇博客所说的解决方法:

sudo pip install --upgrade cryptography
sudo python -m easy_install --upgrade pyOpenSSL

然后,没有警告,出现另一个错误:

rogn@ubuntu:~$ pip -V
Traceback (most recent call last):
  File "/usr/bin/pip", line 11, in <module>
    sys.exit(__main__._main())
AttributeError: 'module' object has no attribute '_main'

根据错误提示我把/usr/bin/pip 文件修改回去:

rogn@ubuntu:~$ sudo vim /usr/bin/pip
rogn@ubuntu:~$ pip -V
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

回到了正常的pip 8.1.1版本,然后奇怪的是,之后怎么也不能升级了:

rogn@ubuntu:~$ sudo pip install --upgrade pip  -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
The directory '/home/rogn/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/rogn/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Looking in indexes: http://mirrors.aliyun.com/pypi/simple/
Requirement already up-to-date: pip in /usr/local/lib/python3.5/dist-packages (19.0.3)

就这样吧,反正一般也用的pip3。

 

pip3的安装

sudo apt-get install python3-pip       #安装pip3
sudo pip3 install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com             #换成阿里镜像,升级pip

同样出现前面的问题,只需修改 /usr/bin/pip 文件。

 

 

参考链接:

1、https://blog.csdn.net/cangcun2619/article/details/80182284

2、https://blog.csdn.net/weixin_39750084/article/details/81813949

3、https://blog.csdn.net/u013187057/article/details/81360917?utm_source=blogxgwz7

4、https://blog.csdn.net/cow66/article/details/80069309

上一篇:centos系统下安装python3以及pip3


下一篇:windows10 Python2和Python3共存