无法再使用 python 2.7 安装 pip?

问题描述

我想使用与 python 2.7(但不是 3.8)兼容的 python 脚本

我需要 pip 才能使脚本正常工作,但看起来我无法再安装 pip 了?我尝试使用 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

解决方法

最新的 pip 有 dropped support for Python 2 并且您无法使用 Python 2.7 通过 get-pip.py 安装最新的 pip。

更新:在这里找到了 Python 2.7 脚本的答案 https://stackoverflow.com/a/65866547/429476


您应该升级到 Python 3。 如果您使用只有 Python2.7 的 Linux 发行版,则可以使用 Linux 包管理器。注意 - 它会安装来自上述脚本的旧版 Pip。

如果您在 Linux 上从包管理器安装 Python,则应始终使用相同的源为该 Python 安装安装 pip。 https://pip.pypa.io/en/stable/installing/ --> https://packaging.python.org/guides/installing-using-linux-tools/

# 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)
,
private adaptRoles(startNode=this.node) {
  const stack = cdk.Stack.of(this);

  startNode.children.forEach((child) => {
    if (child instanceof iam.Role) {
      const roleResource = child.node.findChild('Resource') as iam.CfnRole;
      const roleName = `some-prefix-${stack.getLogicalId(roleResource)}`.slice(0,64);

      roleResource.addPropertyOverride('PermissionsBoundary',`arn:aws:iam::${stack.account}:policy/some-boundary`);
      roleResource.addPropertyOverride('RoleName',roleName);

      // cdk.Tags.of(child|roleResource).add(...) has no effect,need to resort to low level override
      roleResource.addPropertyOverride('Tags',[
        {
          Key: 'Technology',Value: 'iam',},{
          Key: 'Name',Value: roleName,]);
    }

    this.adaptRoles(child.node);
  });
}

protected prepare() {
  // makes no difference changing the order of the statements
  this.adaptRoles();
  super.prepare();
}
,

问题似乎是没有指定 pip 的特定版本,因此脚本试图安装最新版本(21 或更高版本)。尝试指定旧版本,例如

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

已记录:https://github.com/pypa/get-pip

,
  1. 此脚本是否与 Python 2.7 兼容?尝试将脚本更新为非弃用版本,然后运行它。

  2. 打开 Python 2.7 安装程序,转到高级选项并查找“安装 pip”复选标记,因为在 Python 的更高版本中确实带有“安装 pip”复选标记,在高级选项中。

  3. 尝试通过手动方法获取模块,即查看所需模块的网站并安装到 C:\Python27\Scripts

如果以上解决方案都没有帮助,我建议您咨询this article。我会通知您,自 2020 年 1 月 1 日起,Python 2.7 已被视为已弃用。

,

一个可行的解决方案:

  1. 已经安装了python2

  2. 安装了 python3(是 3)

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

  4. 找到它的安装位置:python3 -m pip show pip

  5. 复制到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. 检查:python2.7 -m pip --version

  7. 重新升级python3的pip。