我的包依赖于BeautifulSoup。如果我通过python setup.py develop
在新的virtualenv中安装我的软件包,我会收到以下错误。如果我第二次执行python setup.py develop
,一切似乎都运行正常。我不知道,发生了什么。如何解决它以获得可重复的设置?
Best match: beautifulsoup4 4.3.2
Downloading https://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.3.2.tar.gz#md5=b8d157a204d56512a4cc196e53e7d8ee
Processing beautifulsoup4-4.3.2.tar.gz
Writing /tmp/easy_install-1eBfi3/beautifulsoup4-4.3.2/setup.cfg
Running beautifulsoup4-4.3.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-1eBfi3/beautifulsoup4-4.3.2/egg-dist-tmp-YmoFSq
Traceback (most recent call last):
File "setup.py", line 73, in <module>
""",
File "/usr/lib/python2.7/distutils/core.py", line 152, 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 "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 27, in run
self.install_for_development()
File "/home/domma/VirtualEnvs/orcid/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 "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 671, in process_distribution
[requirement], self.local_index, self.easy_install
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 564, in resolve
dist = best[req.key] = env.best_match(req, self, installer)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 802, in best_match
return self.obtain(req, installer) # try and download/install
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/pkg_resources.py", line 814, in obtain
return installer(requirement)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 593, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 623, in install_item
dists = self.install_eggs(spec, download, tmpdir)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 809, in install_eggs
return self.build_and_install(setup_script, setup_base)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1015, in build_and_install
self.run_setup(setup_script, setup_base, args)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 1000, in run_setup
run_setup(setup_script, args)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 50, in run_setup
lambda: execfile(
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 100, in run
return func()
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/sandbox.py", line 52, in <lambda>
{'__file__':setup_script, '__name__':'__main__'}
File "setup.py", line 27, in <module>
'raven',
File "/usr/lib/python2.7/distutils/core.py", line 152, 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 970, in run_command
cmd_obj = self.get_command_obj(command)
File "/usr/lib/python2.7/distutils/dist.py", line 846, in get_command_obj
cmd_obj = self.command_obj[command] = klass(self)
File "/home/domma/VirtualEnvs/orcid/local/lib/python2.7/site-packages/setuptools/__init__.py", line 69, in __init__
_Command.__init__(self,dist)
File "/usr/lib/python2.7/distutils/cmd.py", line 59, in __init__
raise TypeError, "dist must be a Distribution instance"
TypeError: dist must be a Distribution instance
答案 0 :(得分:4)
此错误与您计算机上安装的distutils
和setuptools
版本之间的差异有关。将setuptools
升级到当前版本可能会解决此问题。
编辑:此解决方案不再适合我(并且显然从未为Jens工作 - 请参阅下面的评论)。现在对我有用的是在我调用的任何脚本之前导入setuptools
之前导致此错误。
许多软件包中的GitHub上的许多问题都讨论了这个错误,但我发现this discussion是最有用的。
答案 1 :(得分:2)
安装dnspython。 pip安装dnspython。或者检查你是否有旧版本的dnspython并升级
答案 2 :(得分:2)
我能够解决问题的唯一方法就是遵循https://bugs.python.org/file37554/distutils_accomodate_distribution_ducktypes.patch 所以 - 我删除了/usr/lib/python2.7/distutils/cmd.py和/usr/lib/python2.7/distutils/cmd.pyc(运行python setup.py develop - 只是为了确保它失败并且是没有使用其他地方的pyc)然后重新创建/usr/lib/python2.7/distutils/cmd.py - 只有这次修补程序中显示的更改。然后,当我再次使用python setup.py时 - 它工作..
答案 3 :(得分:1)
尝试使用pip安装软件包
$ pip install -e path/to/your/Project
有关详细信息,请参阅http://pip.readthedocs.org/en/latest/reference/pip_install.html#editable-installs。
答案 4 :(得分:1)
当我遇到这个时,乍一看似乎是在抱怨 Distribution()
没有生成 Distribution
实例,但这只是部分正确。
setuptools
提供自己的 Distribution
,并将其猴子修补到 distutils
。这在大多数情况下都有效,但如果您在导入 Distribution
并完成其魔法之前获得对 setuptools
的引用,则会失败。
脚本顶部如下:
from distutils.dist import Distribution
然后我们导入并使用了 setuptools
的各个部分。
就我而言,解决方案是在使用它的函数中进行延迟导入,以便在加载 Distribution
后获得 setuptools
。