构建包期间没有名为"版本"的模块



我试图构建一个自定义python包,与pyproject.toml。我添加了一个setup.py只是为了一个开发和可编辑的环境。(参见https://snarky.ca/what-the-heck-is-pyproject-toml/)pyproject-toml文件:

[build-system]
requires = ["setuptools == 44.1.1", "wheel"]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
testpaths = ["tests"]

我用python3 -m pip install --upgrade build升级了python构建

当我运行python3 -m build时,我得到这个错误:

...
Successfully installed setuptools-44.1.1 wheel-0.36.2
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pep517/_in_process.py", line 280, in <module>
main()
File "/usr/lib/python3/dist-packages/pep517/_in_process.py", line 263, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/lib/python3/dist-packages/pep517/_in_process.py", line 114, in get_requires_for_build_wheel
return hook(config_settings)
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/build_meta.py", line 146, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/build_meta.py", line 127, in _get_build_requires
self.run_setup()
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/build_meta.py", line 142, in run_setup
exec(compile(code, __file__, 'exec'), locals())
File "setup.py", line 6, in <module>
setuptools.setup()
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/__init__.py", line 162, in setup
return distutils.core.setup(**attrs)
File "/usr/lib/python3.9/distutils/core.py", line 121, in setup
dist.parse_config_files()
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/_virtualenv.py", line 21, in parse_config_files
result = old_parse_config_files(self, *args, **kwargs)
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/dist.py", line 701, in parse_config_files
parse_configuration(self, self.command_options,
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 121, in parse_configuration
meta.parse()
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 426, in parse
section_parser_method(section_options)
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 399, in parse_section
self[name] = value
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 184, in __setitem__
value = parser(value)
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 515, in _parse_version
version = self._parse_attr(value, self.package_dir)
File "/tmp/build-env-qw5973cj/lib/python3.9/site-packages/setuptools/config.py", line 349, in _parse_attr
module = import_module(module_name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'version'
ERROR Backend subproccess exited when trying to invoke get_requires_for_build_wheel

我不明白错误的来源,这似乎与我的代码没有链接。

人们通常在模块(一个名为version.py的文件)中设置变量__version__,以指定版本信息,并使其可供全世界查看,详细说明请参见pep-0396。因此,回溯可能表明包中缺少版本文件。

可能,它在构建pyproject时读取setup.py(或setup.cfg等)。(只使用setuptools作为[build-system]??) .

你可以写&;from version importversion";你的设置里还有别的东西吗?

删除setup.py或将setup.py重命名为setup_ .py,例如

我Env .

  • setuptools: 67.6.0
[build-system]
requires = ["setuptools", "setuptools_scm"]
build-backend = "setuptools.build_meta"

相关内容

  • 没有找到相关文章

最新更新