【问题标题】:Why did a new version of a library get installed when the current one satisfied setup.py requirements?当当前库满足 setup.py 要求时,为什么要安装新版本的库?
【发布时间】:2019-09-10 16:08:13
【问题描述】:

我开发了一个使用matplotlib 的包,因此我在我的项目的setup.py 中添加了以下行:(link to setup.py)

install_requires=[
    'matplotlib>=2.0.0',
    ...other libs
]

但是,当我尝试将我的包安装到一个 已经安装了 matplolib 2.1.0 版的 virtualenv(通过 pip install)中时,pip 获取并安装了 matplotlib 3 版不管。

这是预期的行为还是这里发生了其他事情?

【问题讨论】:

  • 你是如何安装包的?
  • @AzatIbrakov pip install dsutil。 (dsutil 是我的库名)

标签: python pip dependencies setuptools


【解决方案1】:

让我尝试一个新的空虚拟环境:

$ pip install matplotlib==2.1.0
Collecting matplotlib==2.1.0
  Downloading https://files.pythonhosted.org/packages/6c/90/cf10bb2020d2811da811a49601f6eafcda022c6ccd296fd05aba093dee96/matplotlib-2.1.0.tar.gz (35.7MB)
    100% |################################| 35.7MB 412kB/s 
Collecting numpy>=1.7.1 (from matplotlib==2.1.0)
  Using cached https://files.pythonhosted.org/packages/45/04/7a738e489a25a9638520a43a0cbfcc4be3ed056266e3110a330a905b36b5/numpy-1.16.2-cp35-cp35m-manylinux1_i686.whl
Collecting six>=1.10 (from matplotlib==2.1.0)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting python-dateutil>=2.0 (from matplotlib==2.1.0)
  Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting pytz (from matplotlib==2.1.0)
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
    100% |################################| 512kB 8.4MB/s 
Collecting cycler>=0.10 (from matplotlib==2.1.0)
  Using cached https://files.pythonhosted.org/packages/f7/d2/e07d3ebb2bd7af696440ce7e754c59dd546ffe1bbe732c8ab68b9c834e61/cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 (from matplotlib==2.1.0)
  Downloading https://files.pythonhosted.org/packages/dd/d9/3ec19e966301a6e25769976999bd7bbe552016f0d32b577dc9d63d2e0c49/pyparsing-2.4.0-py2.py3-none-any.whl (62kB)
    100% |################################| 71kB 10.8MB/s 
Building wheels for collected packages: matplotlib
  Building wheel for matplotlib (setup.py) ... done
  Stored in directory: /home/phd/.cache/pip/wheels/a7/99/eb/b5566219ff5a526f98e802144d551feaa6b9340b3569bf86df
Successfully built matplotlib
Installing collected packages: numpy, six, python-dateutil, pytz, cycler, pyparsing, matplotlib
Successfully installed cycler-0.10.0 matplotlib-2.1.0 numpy-1.16.2 pyparsing-2.4.0 python-dateutil-2.8.0 pytz-2019.1 six-1.12.0

$ pip install dsutil
Collecting dsutil
  Downloading https://files.pythonhosted.org/packages/17/58/ea2ccb9d071040eb5baa16b91327a6799decec6cfbfb12222388e37951d7/dsutil-0.1.1-py3-none-any.whl
Collecting scikit-learn>=0.20.0 (from dsutil)
  Downloading https://files.pythonhosted.org/packages/ee/40/d5e691b6f103f5cdfbd2e1468cb172f2267224844330ffe494409ff6a3d5/scikit_learn-0.20.3-cp35-cp35m-manylinux1_i686.whl (4.9MB)
    100% |################################| 4.9MB 4.3MB/s 
Collecting pandas>=0.20.0 (from dsutil)
  Downloading https://files.pythonhosted.org/packages/b1/57/069982c126d22bbdb4de71912eec2c1d8d303149a0d7b17927797479a0ed/pandas-0.24.2-cp35-cp35m-manylinux1_i686.whl (8.7MB)
    100% |################################| 8.7MB 3.0MB/s 
Requirement already satisfied: matplotlib>=2.0.0 in ./lib/python3.5/site-packages (from dsutil) (2.1.0)
Requirement already satisfied: numpy>=1.8.2 in ./lib/python3.5/site-packages (from scikit-learn>=0.20.0->dsutil) (1.16.2)
Collecting scipy>=0.13.3 (from scikit-learn>=0.20.0->dsutil)
  Using cached https://files.pythonhosted.org/packages/19/7b/fdd034bbd1c266b05bc5c38bc91e6733c0e19bc9d3630fd32d869998b6e3/scipy-1.2.1-cp35-cp35m-manylinux1_i686.whl
Requirement already satisfied: python-dateutil>=2.5.0 in ./lib/python3.5/site-packages (from pandas>=0.20.0->dsutil) (2.8.0)
Requirement already satisfied: pytz>=2011k in ./lib/python3.5/site-packages (from pandas>=0.20.0->dsutil) (2019.1)
Requirement already satisfied: cycler>=0.10 in ./lib/python3.5/site-packages (from matplotlib>=2.0.0->dsutil) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in ./lib/python3.5/site-packages (from matplotlib>=2.0.0->dsutil) (2.4.0)
Requirement already satisfied: six>=1.10 in ./lib/python3.5/site-packages (from matplotlib>=2.0.0->dsutil) (1.12.0)
Installing collected packages: scipy, scikit-learn, pandas, dsutil
Successfully installed dsutil-0.1.1 pandas-0.24.2 scikit-learn-0.20.3 scipy-1.2.1

看到了吗? matplotlib 未升级。 已经满足要求:matplotlib>=2.0.0。您能否显示您终端的类似输出,以便我们更好地了解发生了什么?

【讨论】:

    【解决方案2】:

    由于您将版本指定为 >=2.0.0 (大于 2.xx),pip 正在安装最新版本 3.xx.

    如果您想安装 2.0.0 版,请尝试使用以下代码:

    install_requires=[
        'matplotlib==2.0.0'
    ]
    

    Link 了解有关版本控制的更多信息。

    【讨论】:

    • 但我不想像那样对版本进行硬编码。即使当前版本已经满足要求,我也想了解哪个 pip 选择更新 matplotlib。
    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 2021-02-21
    • 2020-02-16
    • 2018-02-18
    • 1970-01-01
    • 2019-11-26
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多