【问题标题】:Python setuptools AttributeError when reading in setup.cfg configuration读取 setup.cfg 配置时的 Python setuptools AttributeError
【发布时间】:2018-10-02 01:14:59
【问题描述】:

我有以下setup.py 文件:

import setuptools
import setuptools.config

_CONFIG = setuptools.config.read_configuration('setup.cfg')

setuptools.setup(
    **_CONFIG
    )

...和setup.cfg 文件:

[metadata]
name = Example
version = 1.0.0
author = First Last
author_email = first.last@example.com
home_page = https://www.github.com/firstlast/example
description = Example is an example project.
long_description = file: README.md
license_file = LICENSE
platform = any
keywords = example
classifiers =
  Programming Language :: Python
  Programming Language :: Python :: 2.7
  Programming Language :: Python :: 3.3
  Programming Language :: Python :: 3.4
  Programming Language :: Python :: 3.5
  Programming Language :: Python :: 3.6
  Programming Language :: Python :: 3.7
  License :: Other/Proprietary License
  Operating System :: OS Independent

[options]
zip_safe = False
include_package_data = True
python_requires = >= 2.7, != 3.0.*, != 3.1.*, != 3.2.*
packages =
  example
setup_requires =
  setuptools
install_requires =
  requests

[options.extras_require]
dev =
  ipython


为了安装模块,我正在执行以下操作:

  1. 使用 pipenv 创建一个虚拟环境。

    $ pipenv --three
    
  2. 激活虚拟环境。

    $ pipenv shell
    
  3. 尝试在虚拟环境中安装example模块。

    $ pip install .
    


当我执行第 3 步时,我收到以下错误:

Processing /Users/firstlast/Stuff/learn/python/setuptools/example
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jw/f2zw3cls6xj20dld1h8st4jc0000gp/T/pip-req-build-rcbbm11x/setup.py", line 37, in <module>
        **_CONFIG
      File "/Users/firstlast/.local/share/virtualenvs/example-tYFXe0D0/lib/python3.7/site-packages/setuptools/__init__.py", line 140, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/Users/firstlast/.local/share/virtualenvs/example-tYFXe0D0/lib/python3.7/site-packages/setuptools/dist.py", line 370, in __init__
        k: v for k, v in attrs.items()
      File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 251, in __init__
        for (opt, val) in cmd_options.items():
    AttributeError: 'bool' object has no attribute 'items'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jw/f2zw3cls6xj20dld1h8st4jc0000gp/T/pip-req-build-rcbbm11x/


setuptools 似乎将zip_file 指定的值用作字典,而实际上它是一个布尔值。


有人可以解释一下我做错了什么吗?



注意

pipenv --three在虚拟环境中安装的Python版本为Python 3.7。

我已经确认在虚拟环境中,setuptools 是最新的(即pip install --upgrade setuptools =>“要求已经是最新的:...(40.4.3 )"),以及 pip 本身(即pip --version == 18.0)。

【问题讨论】:

    标签: python setuptools


    【解决方案1】:

    setup.cfg 不是这样使用的。 read_configuration() 仅供非setuptools 代码使用,希望读取setup.cfg;无需在您自己的setup.py 中调用它,因为setup() 会自行读取和处理setup.cfg。只需将您的 setup.py 更改为:

    import setuptools
    
    setuptools.setup()
    

    【讨论】:

    • 啊,非常感谢!对不起这个愚蠢的问题。我浏览了 setuptools “readthedocs”,但发现有些不清楚。
    猜你喜欢
    • 2022-01-10
    • 2014-10-26
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    • 2018-12-12
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多