Python 打包模块的版本冲突问题

Version conflict issue with Python packaging module

我正在使用 stack.sh

部署 OpenStack Newton devstack

我运行进入以下问题:

Processing /opt/stack/requirements
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-2UrvLp-build/setup.py", line 29, in <module>
        pbr=True)
      File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/opt/stack/requirements/.venv/local/lib/python2.7/site-packages/setuptools/dist.py", line 320, in __init__
        _Distribution.__init__(self, attrs)
      File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
        self.finalize_options()
      File "/opt/stack/requirements/.venv/local/lib/python2.7/site-packages/setuptools/dist.py", line 386, in finalize_options
        ep.require(installer=self.fetch_build_egg)
      File "/opt/stack/requirements/.venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2318, in require
        items = working_set.resolve(reqs, env, installer, extras=self.extras)
      File "/opt/stack/requirements/.venv/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 859, in resolve
        raise VersionConflict(dist, req).with_context(dependent_req)
    pkg_resources.VersionConflict: (packaging 16.7 (/opt/stack/requirements/.venv/lib/python2.7/site-packages), Requirement.parse('packaging>=16.8'))

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-2UrvLp-build/
+inc/python:pip_install:1                  exit_trap
+./stack.sh:exit_trap:487                  local r=1
++./stack.sh:exit_trap:488                  jobs -p
+./stack.sh:exit_trap:488                  jobs=
+./stack.sh:exit_trap:491                  [[ -n '' ]]
+./stack.sh:exit_trap:497                  kill_spinner
+./stack.sh:kill_spinner:383               '[' '!' -z '' ']'
+./stack.sh:exit_trap:499                  [[ 1 -ne 0 ]]
+./stack.sh:exit_trap:500                  echo 'Error on exit'
Error on exit
+./stack.sh:exit_trap:501                  generate-subunit 1486635146 55 fail
+./stack.sh:exit_trap:502                  [[ -z /opt/stack/logs ]]
+./stack.sh:exit_trap:505                  /home/demo/devstack/tools/worlddump.py -d /opt/stack/logs
World dumping... see /opt/stack/logs/worlddump-2017-02-09-101322.txt for details
+./stack.sh:exit_trap:511                  exit 1

似乎名为 'packaging' 的软件包存在版本冲突。

这是我所做的 - > 尝试通过执行以下操作卸载并重新安装软件包:

pip uninstall packaging

pip install --upgrade packaging

但这并没有真正帮助我,我又遇到了同样的错误。

请帮我解决这个问题,请具体说明我应该在哪个目录下执行哪个命令。

我在 devstack 中遇到了完全相同的错误,以下是修复方法:

首先添加一个全局设置来记录 pip 所做的一切。使用以下内容创建 /etc/pip.conf

[global]
log = /var/log/pip.log

然后运行:

sudo touch /var/log/pip.log
sudo chmod a+rw /var/log/pip.log

确保 pip 始终可以写入此文件。

然后查看打包包相关的变化:

tail -f /var/log/pip.log |grep packaging

并并行重新启动 ./stack.sh .

在某些时候,在 pip 日志中您应该会看到类似于以下内容的一行:

Setting packaging===16.7 (from -c /opt/stack/requirements/upper-constraints.txt ...

这向您显示了此要求的来源,在本例中它来自 /opt/stack/requirements/upper-constraints.txt 文件。

然后您可以手动编辑有问题的文件来更改此要求以消除冲突。就我而言,我更换了:

packaging===16.7

来自

packaging>=16.8

/opt/stack/requirements/upper-constraints.txt

之后,devstack 安装顺利完成。


TL;DR

cd /opt/stack/requirements/
sed -i.bak s/packaging===16.7/packaging>=16.8/g upper-contraints.txt