gpt4 book ai didi

python - 导入错误 : The 'packaging.requirements' package is required

转载 作者:行者123 更新时间:2023-11-28 17:57:19 31 4
gpt4 key购买 nike

我在 ubuntu 上运行 VPS:

Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty

我尝试将 Python 从 2.7.6 升级到 2.7.16。

刚升级后Gunicorn库启动失败

Traceback (most recent call last):
File "/home/user/bin/python-2.7/bin/gunicorn", line 7, in <module>
from gunicorn.app.wsgiapp import run
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 9, in <module>
from gunicorn.app.base import Application
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/app/base.py", line 12, in <module>
from gunicorn import util
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/util.py", line 12, in <module>
import pkg_resources
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/__init__.py", line 82, in <module>
__import__('pkg_resources.extern.packaging.requirements')
File "/home/user/bin/python-2.7/lib/python2.7/site-packages/pkg_resources/extern/__init__.py", line 61, in load_module
"distribution.".format(**locals())
ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.

有人告诉我这可能是一些设置工具的问题,所以我更新了它们

python -m ensurepip
Looking in links: /tmp/tmp98U8zf
Requirement already satisfied: setuptools in ./bin/python-2.7/lib/python2.7/site-packages (41.1.0)
Requirement already satisfied: pip in ./bin/python-2.7/lib/python2.7/site-packages (19.2.2)

(无变化)

我试过

pip install packaging

(无变化)

或将 setuptools 降级到 19.2(如 Python 2.7 The 'packaging' package is required; normally this is bundled with this package 中所建议)

得到了

  File "/home/user/bin/python-2.7/lib/python2.7/site-packages/gunicorn/config.py", line 8, in <module>
import copy
File "/home/user/bin/python-2.7/lib/python2.7/copy.py", line 52, in <module>
import weakref
File "/home/user/bin/python-2.7/lib/python2.7/weakref.py", line 14, in <module>
from _weakref import (
ImportError: cannot import name _remove_dead_weakref

在我的案例中,是否有升级到 2.7.16 python 的有效方法?

更新:

我用它升级了python

wget https://www.python.org/ftp/python/2.7.16/Python-2.7.16.tgz
make clean && ./configure --enable-unicode=ucs4 --enable-shared --prefix=/home/user/bin/python-2.7/ --with-ensurepip=install && make && make install
pip install -r ~/django/django_projects/requirements.txt

点卡住:https://www.pastiebin.com/5d592ea701503

谢谢。

最佳答案

场景

首先:在尝试执行Python脚本时,出现如下错误信息:

ImportError: The 'packaging.requirements' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.

第二:当尝试使用 pip show setuptools 检查 setuptools 的版本时(或当使用任何其他 pip 命令),出现下一条错误消息:

ImportError: cannot import name _remove_dead_weakref

原因

这是因为当前的 Python 安装不知何故搞砸了。在我的例子中,困惑是由从 Ubuntu 16.04 升级到 Ubuntu 18.04 造成的。

解决方案

虚拟环境

在最好的情况下,您已经在使用虚拟环境(这是我的情况)。这里的解决方案是再次重新创建/设置您的 venv ( step-by-step ):

$ cd /path/to/your/venv

# remove your old venv
$ rm -rf ./*

# create a new one
$ /usr/bin/virtualenv . --python=YOUR-PYTHON-VERSION

# activate venv
$ source bin/activate

# verify the correct python version is installed
$ python --version

例如将 YOUR-PYTHON-VERSION 替换为 python2.7python3.7

重新创建您的 venv 后,问题应该得到解决,您应该可以再次使用 pip。

没有虚拟环境

我认为解决该问题的最佳方法是完全卸载所有非默认 Python 版本(例如 Ubuntu 18.04Python 3.6+ 一起提供),然后彻底重新安装所需的所有其他 Python 版本。

关于python - 导入错误 : The 'packaging.requirements' package is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57543808/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com