如何在使用 Python 2 时正确避免出现“您正在 Python 2 上运行 Setuptools,它不再受支持”的消息?

如何在使用 Python 2 时正确避免出现“您正在 Python 2 上运行 Setuptools,它不再受支持”的消息?

我刚刚在新系统上安装了 Ubuntu 16.04 LTS。
我需要在其上运行一些 Python 2 的东西。

所以我做了以下事情:

$ pip2
The program 'pip2' is currently not installed. You can install it by typing:
sudo apt install python-pip
$ sudo apt-get install python-pip
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libexpat1-dev libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-dev python-pip-whl python-setuptools
  python-wheel python2.7-dev
Suggested packages:
  python-setuptools-doc
The following NEW packages will be installed:
  libexpat1-dev libpython-all-dev libpython-dev libpython2.7 libpython2.7-dev python-all python-all-dev python-dev python-pip python-pip-whl
  python-setuptools python-wheel python2.7-dev
0 upgraded, 13 newly installed, 0 to remove and 0 not upgraded.
Need to get 30.7 MB of archives.
After this operation, 48.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...

然后我开始使用pip2

$ which pip2
/usr/bin/pip2
$ pip2 install --user jsonmerge
...

然后失败了:

$ pip2 install --user zipp
/home/xenial/.local/lib/python2.7/site-packages/pkg_resources/py2_warn.py:22: UserWarning: Setuptools will stop working on Python 2
************************************************************
You are running Setuptools on Python 2, which is no longer
supported and
>>> SETUPTOOLS WILL STOP WORKING <<<
in a subsequent release (no sooner than 2020-04-20).
Please ensure you are installing
Setuptools using pip 9.x or later or pin to `setuptools<45`
in your environment.
If you have done those things and are still encountering
this message, please comment in
https://github.com/pypa/setuptools/issues/1458
about the steps that led to this unsupported combination.
************************************************************
  sys.version_info < (3,) and warnings.warn(pre + "*" * 60 + msg + "*" * 60)
Collecting zipp
Installing collected packages: zipp
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 335, in run
    prefix=options.prefix_path,
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 732, in install
    **kwargs
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 837, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 1039, in move_wheel_files
    isolated=self.isolated,
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 346, in move_wheel_files
    assert info_dir, "%s .dist-info directory not found" % req
AssertionError: zipp .dist-info directory not found
You are using pip version 8.1.1, however version 20.0.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

(上面的 PyPi 包仅作为示例,我在具有 PyPi 的其他包的系统上也看到过这个问题)。

我应该如何以正确的方式解决这个问题?

答案1

我们需要遵循输出最后两行中的建议:

您使用的是 pip 版本 8.1.1,但可以使用版本 20.0.2。
您应该考虑通过“pip install --upgrade pip”命令进行升级。

所以我们需要运行

pip2 install --upgrade --user pip

然后注销并重新登录,然后按照其他建议:

使用 pip 9.x 或更高版本安装工具或将其固定到setuptools<45您的环境中。

pip2 install --user "setuptools<45"

此后,任何pip2-packages 的安装都将导致出现以下消息:

弃用:Python 2.7 已于 2020 年 1 月 1 日终止使用。请升级您的 Python,因为 Python 2.7 不再维护。pip 的未来版本将不再支持 Python 2.7。有关 pip 中 Python 2 支持的更多详细信息,请参阅https://pip.pypa.io/en/latest/development/release-process/#python-2-support

相关内容