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

Posted

技术标签:

【中文标题】构建包期间没有名为“版本”的模块【英文标题】:No module named 'version' during building package 【发布时间】:2021-10-05 20:16:12 【问题描述】:

我正在尝试使用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

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于构建包期间没有名为“版本”的模块的主要内容,如果未能解决你的问题,请参考以下文章

用pip下载自己的模块,“没有名为......的模块”

导入错误:没有名为 arch 的模块

使用Go Module构建项目

在安装 ElectronJS 应用程序期间安装节点模块

没有名为“PyQt5.sip”的模块

即使使用较旧的 spark 版本,也没有名为“pyspark.streaming.kafka”的模块