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

转载于:https://www.cnblogs.com/lfri/p/10425454.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值