如何查找哪个包依赖于 “futures” 在 requirements.txt 中

huangapple go评论65阅读模式
英文:

How to find out which package depends on "futures" in requirements.txt

问题

我已经在requirements.txt中定义了许多pip包,但我没有定义" futures "包:

...
future == 0.18.3
six == 1.16.0
joblib == 1.2.0
...

然后在Ubuntu 22.04上使用以下命令下载所有包:

pip3.9 download -r "/home/requirements.txt"

上述命令退出并显示以下错误:

...
...
Collecting widgetsnbextension~=4.0.7
  Downloading widgetsnbextension-4.0.7-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 3.9 MB/s eta 0:00:00
Collecting branca>=0.5.0
  Downloading branca-0.6.0-py3-none-any.whl (24 kB)
Collecting traittypes<3,>=0.2.1
  Downloading traittypes-0.2.1-py2.py3-none-any.whl (8.6 kB)
Collecting xyzservices>=2021.8.1
  Downloading xyzservices-2023.5.0-py3-none-any.whl (56 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.5/56.5 KB 1.3 MB/s eta 0:00:00
Collecting futures
  Downloading futures-3.0.5.tar.gz (25 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [25 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 14, in <module>
        File "/python39/lib/python3.9/site-packages/setuptools/__init__.py", line 18, in <module>
          from setuptools.dist import Distribution
        File "/python39/lib/python3.9/site-packages/setuptools/dist.py", line 32, in <module>
          from setuptools.extern.more_itertools import unique_everseen
        File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
        File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
        File "<frozen importlib._bootstrap>", line 565, in module_from_spec
        File "/python39/lib/python3.9/site-packages/setuptools/extern/__init__.py", line 52, in create_module
          return this_module._post_import_redirect_module(spec, spec.loader, globals(), this_module)
        File "/python39/lib/python3.9/site-packages/setuptools/extern/__init__.py", line 37, in _post_import_redirect_module
          __import__(extant)
        File "/python39/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/__init__.py", line 1, in <module>
          from .more import *  # noqa
        File "/python39/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/more.py", line 5, in <module>
          from concurrent.futures import ThreadPoolExecutor
        File "/tmp/pip-download-jelw4tc2/futures/concurrent/futures/__init__.py", line 8, in <module>
          from concurrent.futures._base import (FIRST_COMPLETED,
        File "/tmp/pip-download-jelw4tc2/futures/concurrent/futures/_base.py", line 357
          raise type(self._exception), self._exception, self._traceback
                                     ^
      SyntaxError: invalid syntax
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> futures

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

如何查找依赖于" futures "的包是在" requirements.txt "中的哪个包?

这是虚拟代码:

# find_out_depends --requirement-file "/home/requirements.txt" --find-depends "futures"

是否有" find_out_depends "命令,可以接受requirements.txt作为参数,然后打印出整个依赖关系树?

英文:

I have defined many pip packages in a requirements.txt, but I have not define the "futures" package:

...
future == 0.18.3
six == 1.16.0
joblib == 1.2.0
...

And then download all packages with the following command on Ubuntu 22.04:

pip3.9 download -r &quot;/home/requirements.txt&quot;

The above command exited with the following error:

...
...
Collecting widgetsnbextension~=4.0.7
  Downloading widgetsnbextension-4.0.7-py3-none-any.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 3.9 MB/s eta 0:00:00
Collecting branca&gt;=0.5.0
  Downloading branca-0.6.0-py3-none-any.whl (24 kB)
Collecting traittypes&lt;3,&gt;=0.2.1
  Downloading traittypes-0.2.1-py2.py3-none-any.whl (8.6 kB)
Collecting xyzservices&gt;=2021.8.1
  Downloading xyzservices-2023.5.0-py3-none-any.whl (56 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.5/56.5 KB 1.3 MB/s eta 0:00:00
Collecting futures
  Downloading futures-3.0.5.tar.gz (25 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  &#215; python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─&gt; [25 lines of output]
      Traceback (most recent call last):
        File &quot;&lt;string&gt;&quot;, line 2, in &lt;module&gt;
        File &quot;&lt;pip-setuptools-caller&gt;&quot;, line 14, in &lt;module&gt;
        File &quot;/python39/lib/python3.9/site-packages/setuptools/__init__.py&quot;, line 18, in &lt;module&gt;
          from setuptools.dist import Distribution
        File &quot;/python39/lib/python3.9/site-packages/setuptools/dist.py&quot;, line 32, in &lt;module&gt;
          from setuptools.extern.more_itertools import unique_everseen
        File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1007, in _find_and_load
        File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 986, in _find_and_load_unlocked
        File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 666, in _load_unlocked
        File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 565, in module_from_spec
        File &quot;/python39/lib/python3.9/site-packages/setuptools/extern/__init__.py&quot;, line 52, in create_module
          return self.load_module(spec.name)
        File &quot;/python39/lib/python3.9/site-packages/setuptools/extern/__init__.py&quot;, line 37, in load_module
          __import__(extant)
        File &quot;/python39/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/__init__.py&quot;, line 1, in &lt;module&gt;
          from .more import *  # noqa
        File &quot;/python39/lib/python3.9/site-packages/setuptools/_vendor/more_itertools/more.py&quot;, line 5, in &lt;module&gt;
          from concurrent.futures import ThreadPoolExecutor
        File &quot;/tmp/pip-download-jelw4tc2/futures/concurrent/futures/__init__.py&quot;, line 8, in &lt;module&gt;
          from concurrent.futures._base import (FIRST_COMPLETED,
        File &quot;/tmp/pip-download-jelw4tc2/futures/concurrent/futures/_base.py&quot;, line 357
          raise type(self._exception), self._exception, self._traceback
                                     ^
      SyntaxError: invalid syntax
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

&#215; Encountered error while generating package metadata.
╰─&gt; futures

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

How to find out which package depends on the "futures" from the "requirements.txt"?

Here is the dummy code:

# find_out_depends --requirement-file &quot;/home/requirements.txt&quot; --find-depends &quot;futures&quot;

Is there any "find_out_depends" command for accepting requirements.txt as argument and then print out the whole dependencies tree?

答案1

得分: 1

创建一个新的 Python 3.9 venv 并安装您的要求 不包括 依赖项:

python3.9 -m pip install --no-deps requirements.txt

然后运行 pip check 命令行工具:

python3.9 -m pip check

它会抱怨某些包存在未满足的依赖关系,并且您应该在其中找到 futures。请不要与 future 混淆,后者是跨平台兼容的。

英文:

Create a fresh Python 3.9 venv and install your requirements without dependencies:

python3.9 -m pip install --no-deps requirements.txt

Then run the pip check CLI:

python3.9 -m pip check

It will complain that some package(s) have unmet dependencies, and you should find futures somewhere in there. Not to be confused with future, which is cross-compat.

答案2

得分: 0

查看这个帖子,你可以使用 pipdeptree 来实现与你所寻找的类似功能:

https://stackoverflow.com/questions/17194301/is-there-any-way-to-show-the-dependency-trees-for-pip-packages

我想你可以编写一个 bash 脚本来在你的 requirements.txt 文件中的每个模块上运行这个命令。

英文:

Check out this thread, you can use pipdeptree to achieve something similar to what you are looking for:

https://stackoverflow.com/questions/17194301/is-there-any-way-to-show-the-dependency-trees-for-pip-packages

I imagine that you could just write a bash script to run this command on every module in your requirements.txt file.

huangapple
  • 本文由 发表于 2023年6月2日 00:17:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383877.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定