pip3没有找到我的包的依赖项,尽管它存在

2024-09-30 08:17:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为我自己的包创建一个setup.py。我的包需要Python依赖项“rarfile”。因此,在{}中,我添加了:

setup(
...
    install_requires=[ 'rarfile' ],
)

不幸的是,当我构建包、将其上载到test.pypi并进行测试安装时,它失败了,并抱怨没有匹配的rarfile发行版。奇怪的是,我可以使用pip3手动安装rarfile,没有任何问题,而且它可以正常工作

在我的软件包上使用pip3进行测试安装:

pip3 install --no-cache-dir --index-url https://test.pypi.org/simple/ droidlysis 
Collecting droidlysis
  Downloading https://test-files.pythonhosted.org/packages/01/e8/f7542484ba4acd6a2d079a22c29cd88dcf63cd8334ffa3de29fa5b0ea7a0/droidlysis-3.0.11.tar.gz (40kB)
    100% |████████████████████████████████| 40kB 975kB/s 
Collecting rarfile==3.1 (from droidlysis)
  Could not find a version that satisfies the requirement rarfile==3.1 (from droidlysis) (from versions: )
No matching distribution found for rarfile==3.1 (from droidlysis)

使用pip3直接安装rarfile

$ pip3 install rarfile==3.1
Collecting rarfile==3.1
  Using cached https://files.pythonhosted.org/packages/88/0b/107dde3f330d04668e126932a09002ac47348841453aa0391634381fa087/rarfile-3.1.tar.gz
Building wheels for collected packages: rarfile
  Running setup.py bdist_wheel for rarfile ... error
  Complete output from command /home/axelle/softs/myvirtualenvs/testdroidlysis/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-yj6ptg3b/rarfile/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpnlukg8ugpip-wheel- --python-tag cp36:
  usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
     or: -c --help [cmd1 cmd2 ...]
     or: -c --help-commands
     or: -c cmd --help

  error: invalid command 'bdist_wheel'

  ----------------------------------------
  Failed building wheel for rarfile
  Running setup.py clean for rarfile
Failed to build rarfile
Installing collected packages: rarfile
  Running setup.py install for rarfile ... done
Successfully installed rarfile-3.1

Tags: installfrompyhttpsorgtestforpackages
3条回答

您使用了 index-url https://test.pypi.org/simple/,因此pip只查看该索引,而不查看其他索引

没有https://test.pypi.org/project/rarfile,因此安装确实失败

或者

  • 使用多个 index-url开关同时包含pypi.org/indextest.pypi.org/index
  • 或者使用 extra-index-urltest.pypi.org/index添加到要搜索的位置

问题在于 index-url URL开关

这将替换默认的pypi.org,并完全忽略它。 使用 extra-index-url URL考虑默认的pypi.org

测试索引does not exist ^{}

{}的帮助:

...
Package Index Options:
  -i,  index-url <url>       Base URL of the Python Package Index (default
                              https://pypi.org/simple). This should point to a
                              repository compliant with PEP 503 (the simple
                              repository API) or a local directory laid out in
                              the same format.
   extra-index-url <url>     Extra URLs of package indexes to use in addition
                              to  index-url. Should follow the same rules as
                               index-url.
...

index-url选项覆盖默认索引url;这并没有增加它。 请改为使用 extra-index-url

$ pip3 install  no-cache-dir  extra-index-url https://test.pypi.org/simple/ droidlysis

相关问题 更多 >

    热门问题