运行setup.py脚本时出现NoneType错误

1 投票
2 回答
721 浏览
提问于 2025-04-18 16:05

在运行 'python setup.py develop' 或 'python setup.py install' 时,我收到了以下错误信息。

Traceback (most recent call last):
  File "setup.py", line 38, in <module>
    test_suite='nose.collector',
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 27, in run
    self.install_for_development()
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 129, in install_for_development
    self.process_distribution(None, self.dist, not self.no_deps)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 682, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 631, in resolve
    dist = best[req.key] = env.best_match(req, ws, installer)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 871, in best_match
    return self.obtain(req, installer)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 883, in obtain
    return installer(requirement)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 595, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 627, in install_item
    self.process_distribution(spec, dist, deps)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in process_distribution
    self.install_egg_scripts(dist)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 152, in install_egg_scripts
    return easy_install.install_egg_scripts(self,dist)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 532, in install_egg_scripts
    self.install_wrapper_scripts(dist)
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 734, in install_wrapper_scripts
    for args in get_script_args(dist):
  File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pbr/packaging.py", line 512, in override_get_script_args
    header = easy_install.get_script_header("", executable, is_wininst)
AttributeError: 'NoneType' object has no attribute 'get_script_header'

有趣的是,如果我再次运行上面的命令,安装就成功了。

为了好玩,我尝试在 pbr/packaging.py 文件中添加调试语句,分别在导入 easy_install 和使用它的时候。导入的时候看起来没问题,但在错误信息提到的第512行访问时却是 None。

下面是我正在使用的需求文件:

pyyaml                                                                                                                                                                                                                                                                 
requests
termcolor
mock
nose
cached_property
argparse
unittest2
tox
stevedore
kombu

还有 setup.py 脚本:

import ez_setup                                                                                                                                                                                                                                                        
ez_setup.use_setuptools('3.6')

import os

from setuptools import setup, find_packages

try:
    # workaround for http://bugs.python.org/issue15881
    import multiprocessing  # noqa
except ImportError:
    pass


def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()


def requirements():
    return read('requirements.txt').splitlines()


setup(
    name='MY_PROJECT',
    version='0.0.1',
    author="Noorez Kassam",
    long_description=read('README.rst'),
    install_requires=requirements(),
    entry_points={
        'console_scripts': [
            'myproj = myproj.myproj:main',
        ],
        'myproj.urloperations.download': [
            'file = myproj.filedownload:download'
        ],
    },  
    packages=find_packages(),
    test_suite='nose.collector',
)

在谷歌上快速搜索了一下,发现其他人也遇到过类似的问题,不过我找不到解决办法。

2 个回答

0

我也遇到过同样的问题,通过更新 setuptools 的版本解决了这个问题,也就是说:

pip install --upgrade setuptools
0

我遇到了一个非常类似的问题,找到了一种解决方法。

我也收到了这个错误信息:AttributeError: 'NoneType' object has no attribute 'get_script_header'

对我有效的解决方法是:在我需要安装的列表中,我把“tornado”放在了“luigi”之前。后来我把顺序改成了先“luigi”,再“tornado”,这个问题就解决了。我注意到你没有使用tornado或luigi,但我猜顺序仍然是导致这个问题的原因,因为你可以通过运行安装命令两次来解决这个问题。

补充说明:在找到这个解决方法之前,我尝试升级到最新的setuptools(版本5.8),但并没有解决这个问题。

撰写回答