V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dangyuluo
V2EX  ›  Python

一个特别奇怪的 pip 包依赖版本问题

  •  
  •   dangyuluo · 2021-06-10 14:03:58 +08:00 · 1384 次点击
    这是一个创建于 1023 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我有一个自己打包 Docker image,里面安装了 numpy 和 matplotlib 。一年前我调试好后 freeze 了所有的 pip package 版本,numpy==1.19.2, matplotlib==3.3.2,自此之后一直没有重新打包 Docker image 。

    最近我需要更改一些东西,因此需要重新打包一下,但是安装这两个 pip 包的时候居然失败了!

    RUN pip3 install numpy==1.19.2 matplotlib==3.3.2
    
    Collecting numpy==1.19.2
      Downloading numpy-1.19.2-cp36-cp36m-manylinux2014_aarch64.whl (12.2 MB)
    Collecting matplotlib==3.3.2
      Downloading matplotlib-3.3.2.tar.gz (37.9 MB)
        ERROR: Command errored out with exit status 1:
         command: /usr/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-vrrk_zeh/matplotlib/setup.py'"'"
    '; __file__='"'"'/tmp/pip-install-vrrk_zeh/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().rep
    lace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-13y
    9rlc7
    ...
          File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 250, in run_setup
            _execfile(setup_script, ns)
          File "/usr/lib/python3/dist-packages/setuptools/sandbox.py", line 45, in _execfile
            exec(code, globals, locals)
          File "/tmp/easy_install-sdqaijla/numpy-1.21.0rc2/setup.py", line 34, in <module>
            # The setuptools version of sdist adds a setup.cfg file to the tree.
        RuntimeError: Python version >= 3.7 required.
    
    

    错误似乎是在说Matplotlib想安装更新的numpy-1.21.0 which 需要 Python3.7 以上。但是我明明有在命令行里指定我想要的 numpy 版本呀?为什么 pip 没有执行呢?

    另外,如果我单独安装numpy,再安装matplotlib问题就消失了。

    RUN pip3 install numpy==1.19.2
    RUN pip3 install matplotlib==3.3.2 # everything works fine
    

    再另外,这个问题只出现在 aarch64 机器上,x86_64 机器一点问题也没有。

    哪位能看出来问题所在?谢谢

    5 条回复    2021-06-11 00:52:10 +08:00
    no1xsyzy
        1
    no1xsyzy  
       2021-06-10 14:21:59 +08:00   ❤️ 1
    这应当是一个 package resolve 的问题
    matplotlib==3.3.2 之后发现想要 numpy,但当前环境下没有 numpy,就自动地寻找了最新版本的 numpy==1.21.0,然后发现 resolve 不行
    这不合理

    不清楚 -r 的话会不会同步,但看你是先 pip freeze 出来的应当是 -r 先发现的吧

    不确定这些工具具体是否能处理,且列一下:
    pip-tools
    Pipenv
    poetry
    no1xsyzy
        2
    no1xsyzy  
       2021-06-10 14:26:12 +08:00
    哦,你是在 Dockerfile 里面 RUN 的啊……
    你可能需要 pip freeze > requirements.txt 然后 pip install -r requirements.txt
    或者上述几个新一代版本依赖管理工具
    xuboying
        3
    xuboying  
       2021-06-10 14:33:00 +08:00   ❤️ 1
    可能是 pip 的 bug ?
    或者应该用 pip -r file 来实现?
    dangyuluo
        4
    dangyuluo  
    OP
       2021-06-10 14:43:39 +08:00
    @no1xsyzy 谢谢,似乎是 python 20.2 之前的 resolver 版本太弱鸡了

    https://github.com/pypa/pip/issues/988
    Hieast
        5
    Hieast  
       2021-06-11 00:52:10 +08:00 via iPhone
    原因上面讨论过了,pip -r 也不管用,我看到有的项目为了简化依赖管理,分了几个 txt 文件依次用 pip 装,就跟你手动先装 numpy 是一样的。

    感觉可以试试 pipenv sync
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2778 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 12:30 · PVG 20:30 · LAX 05:30 · JFK 08:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.