尝试安装和测试我的软件包时遇到错误。
该错误是由于两个软件包的传递依赖关系版本冲突引起的-一个在setup_requires
(twine
)中,另一个在install_requires
(tensorflow
)中。
两者都暂时依赖于bleach
,每个版本都有不同的版本。
使用pip install -e .
或python setup.py develop
安装软件包可以正常工作。
运行python setup.py test
时会发生错误(请注意:仅在安装 后运行测试时才会发生。如果未先安装软件包,则没有错误)。
Traceback (most recent call last):
File "setup.py", line 3, in <module>
setup()
File "/usr/local/lib/python3.6/site-packages/setuptools/__init__.py", line 145, in setup
return distutils.core.setup(**attrs)
File "/usr/local/lib/python3.6/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/lib/python3.6/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/root/test/.eggs/pytest_runner-4.4-py3.6.egg/ptr.py", line 189, in run
with self.project_on_sys_path():
File "/usr/local/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.6/site-packages/setuptools/command/test.py", line 166, in project_on_sys_path
require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 791, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (bleach 3.1.0 (/root/test/.eggs/bleach-3.1.0-py3.6.egg), Requirement.parse('bleach==1.5.0'), {'tensorboard'})
使用最小的包装结构会出现错误:
my-package
|-- src/
| |-- module.py (empty)
|-- setup.py
|-- setup.cfg
setup.cfg看起来像这样:
[metadata]
name = test
version = 0.0.1
[options]
package_dir=
= src
packages=find:
setup_requires =
setuptools >= 40.0.0
pip >= 10
pytest-runner >= 2.0
twine >= 1.0.0
install_requires =
tensorflow == 1.6.0
tests_require =
pytest >=3.0, <4.0
[options.packages.find]
where=src
[aliases]
test=pytest
setup.py看起来像这样:
from setuptools import setup
setup()
步骤:
pip install -e .
python setup.py test
环境:
python:3.6
Docker映像据我所知,在运行命令(安装和测试)时,将安装setup_requires
中的软件包,并将egg文件放置在.eggs目录中。
运行python setup.py test
时,setuptools从install_requires
安装所有软件包,但发现其中一个依赖项已经存在一个鸡蛋,并使用它。
我不确定确切的机制是什么。
twine
中删除setup_requires
-我意识到它不是设置必需的python setup.py test
尽管在这种情况下我能够解决问题,但我仍然想更多地了解导致问题的原因。