首页 > 解决方案 > pipenv 不安装 GitHub 包的依赖项

问题描述

我有一个 python 包上传到 GitHub。这个包使用 Pipenv 来管理依赖。另一方面,我有一个使用该库的 python 工具(并使用 Pipenv 来管理它自己的依赖项)。

查看我的包的 Pipfile,我们可以看到它有两个依赖项:

[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"
loggly-python-handler = "*"

[dev-packages]
pylint = "*"

[requires]
python_version = "3.7"

在我的 python 工具中,我使用以下方法安装了我的包: pipenv install -e git+https://github.com/<name>/<name>.git#egg=<name>

但是,在检查该工具的 pip 图时,看起来我的包没有依赖项:

(tool-aqleTTYE) C:\Projects\tool>pipenv graph
<my_package>==0.0.3
pylint==2.0.1
  - astroid [required: >=2.0.1, installed: 2.0.1]
    - lazy-object-proxy [required: Any, installed: 1.3.1]
    - six [required: Any, installed: 1.11.0]
    - wrapt [required: Any, installed: 1.10.11]
  - colorama [required: Any, installed: 0.3.9]
  - isort [required: >=4.2.5, installed: 4.3.4]
  - mccabe [required: Any, installed: 0.6.1]

我希望看到我的包依赖于requestsand loggly-python-handler。事实上,在运行代码时它说它找不到包依赖项..

pipenv run python tool.py

    ....


  File "c:\.virtualenvs\tool-aqlettye\src\tool\tool\logger.py", line 35, in <module>
    'level': 'DEBUG',
  File "c:\python37\Lib\logging\config.py", line 792, in dictConfig
    dictConfigClass(config).configure()
  File "c:\python37\Lib\logging\config.py", line 563, in configure
    '%r' % name) from e
ValueError: Unable to configure handler 'loggly'

只是为了确定:

(tool-aqleTTYE) C:\Projects\tool>python
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'

这是一个错误还是我做错了什么?

标签: pythongithubpackagevirtualenvpipenv

解决方案


尝试:

pipenv lock --clear

这应该清除您的锁定文件。它对我有用。

只需卸载并安装后:

pipenv uninstall --all

然后

pipenv install

我第一次创建的自定义包(.whl)遇到了同样的问题,但没有在“setup.py”中定义依赖项(install_requires)。我将它上传到个人 pypi 存储库并安装它。在更正我的错误并使用要求更新它并重试安装它之后,依赖项不起作用。

我发现锁定文件没有显示依赖项更改,但“pipenv 图”显示了它们。

然后我在这里找到了命令


推荐阅读