pipとpip 3のインストール、アップグレード、バージョンの表示、および問題点

5417 ワード

pipの取り付け


問題1

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 
    from pip import main

なぜなら、pip 10.0.0以降はmain()がないからだそうです.

方法1


次のように、バージョンを下げることを考慮します.10.0.0でいいです.
python -m pip install --upgrade pip==9.0.3

これからは勝手にアップグレードしないでください.

方法2


このブログでは、/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で、問題は解決します!
 

問題2


次は死の過程ですから、自分で無視してください.
前の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 
    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)

そうしましょう.どうせ普通に使うpip 3です.
 

pip 3の取り付け

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