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             #換成阿里鏡像,升級pip3
sudo apt-get remove --purge python3-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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM