简体   繁体   English

不能再使用 python 2.7 安装 pip?

[英]can't install pip anymore with python 2.7?

I wanted to use a python script compatible with python 2.7 (but not 3.8)我想使用与 python 2.7(但不是 3.8)兼容的 python 脚本

I need pip to make the script work but looks like I can't install pip anymore?我需要 pip 才能使脚本正常工作,但看起来我不能再安装 pip 了? I tried with get-pip.py, but it's not working:我尝试使用 get-pip.py,但它不起作用:

user@DESKTOP-J9T7UBF
$ get-pip.py
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
c:\users\user\appdata\local\temp\tmp2kztqk\pip.zip\pip\_vendor\urllib3\util\ssl_.py:387: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

The latest pip has dropped support for Python 2 And you cannot install the latest pip via get-pip.py using Python 2.7. The latest pip has dropped support for Python 2 And you cannot install the latest pip via get-pip.py using Python 2.7.

Update: Found an answer here with the script for Python 2.7 https://stackoverflow.com/a/65866547/429476 .更新:在 Python 2.7 https://stackoverflow.com/a/65866547/429476的脚本中找到了答案。


You should upgrade to Python 3. You can use your Linux package manager if you using a Linux distro which have only Python2.7. You should upgrade to Python 3. You can use your Linux package manager if you using a Linux distro which have only Python2.7. Note - it installs an older version of Pip that that comes from above script.注意 - 它安装了来自上述脚本的旧版本 Pip。

If you installed Python from a package manager on Linux, you should always install pip for that Python installation using the same source. If you installed Python from a package manager on Linux, you should always install pip for that Python installation using the same source. https://pip.pypa.io/en/stable/installing/ --> https://packaging.python.org/guides/installing-using-linux-tools/ https://pip.pypa.io/en/stable/installing/ --> https://packaging.python.org/guides/installing-using-linux

# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1883k  100 1883k    0     0  6584k      0 --:--:-- --:--:-- --:--:-- 6584k

# python get-pip.py --user

Traceback (most recent call last):
  File "get-pip.py", line 24226, in <module>
    main()
  File "get-pip.py", line 199, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    from pip._internal.cli.main import main as pip_entry_point
  File "/tmp/tmpyG_UJ3/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax
# sudo apt-get install python-pip
# python -m pip --version
pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)
pip install --upgrade "pip < 21.0"

A working solution:一个可行的解决方案:

  1. Have an installed python2已安装 python2

  2. Have an installed python3 (yes 3)安装了python3(是3)

  3. Install a legacy pip to python3 (eg 9): python3 -m pip install --upgrade "pip==9"将旧版 pip 安装到 python3(例如 9): python3 -m pip install --upgrade "pip==9"

  4. Find where it has been installed to: python3 -m pip show pip找到它的安装位置: python3 -m pip show pip

  5. Copy to python2's PATH:复制到python2的PATH:

    sudo cp -r /home/usr/.local/lib/python3.8/site-packages/pip-9.0.0.dist-info/ /usr/local/lib/python2.7/dist-packages/

    sudo cp -r /home/raczb/.local/lib/python3.8/site-packages/pip /usr/local/lib/python2.7/dist-packages/

  6. Check: python2.7 -m pip --version检查: python2.7 -m pip --version

  7. Re-upgrade python3's pip.重新升级python3的pip。

The problem seems to be that no specific version of pip was specified, and therefore, the script is trying to install the latest version (21 or later).问题似乎是没有指定pip的特定版本,因此,脚本正在尝试安装最新版本(21 或更高版本)。 Try specifying an older version, eg尝试指定旧版本,例如

python get-pip.py 'pip==20.3.1'

Documented: https://github.com/pypa/get-pip记录在案:https://github.com/pypa/get-pip

  1. Is this script only compatible with Python 2.7?此脚本是否与 Python 2.7 兼容? Try to update the script to a non-deprecated version, then run it.尝试将脚本更新为非弃用版本,然后运行它。

  2. Open the Python 2.7 installer, go to Advanced options and look for an 'Install pip ' checkmark, since in the later releases of Python did come with an 'Install pip ' checkmark, in Advanced options. Open the Python 2.7 installer, go to Advanced options and look for an 'Install pip ' checkmark, since in the later releases of Python did come with an 'Install pip ' checkmark, in Advanced options.

  3. Try attaining the module by manual methods ie Look on the website of the desired module and install to C:\Python27\Scripts .尝试通过手动方法获取模块,即查看所需模块的网站并安装到C:\Python27\Scripts

If none of the above solutions are of assistance, I suggest you consult this article .如果以上解决方案都没有帮助,我建议您参考这篇文章 I will inform you that Python 2.7 was considered as deprecated as of January 1st, 2020.我会通知您,自 2020 年 1 月 1 日起,Python 2.7 被视为已弃用。

Yeah pip has dropped it's support to python 2.7.是的 pip 已放弃对 python 2.7 的支持。 If you still want to use it for python 2.7, downgrading the pip will help you:如果您仍想将它用于 python 2.7,降级 pip 将帮助您:

sudo easy_install pip==20.3.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM