构建包期间没有名为 'version' 的模块
No module named 'version' during building package
我正在尝试使用 pyproject.toml
构建自定义 python 程序包。我为开发和可编辑环境添加了一个 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
我不明白错误的来源,我的代码似乎没有 link。
人们通常在一个模块中设置变量__version__
,一个名为version.py
的文件,以指定版本信息并使其可供全世界检查,参见pep-0396详细解释。所以回溯可能表明你的包中缺少版本文件。
我正在尝试使用 pyproject.toml
构建自定义 python 程序包。我为开发和可编辑环境添加了一个 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
当我 运行 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
我不明白错误的来源,我的代码似乎没有 link。
人们通常在一个模块中设置变量__version__
,一个名为version.py
的文件,以指定版本信息并使其可供全世界检查,参见pep-0396详细解释。所以回溯可能表明你的包中缺少版本文件。