Why does installing a python package break setuptools and causes pkg_resources to not be found?

本秂侑毒 提交于 2019-12-05 17:08:59

I'm not sure about all of your problems but there is at least one problem caused by the loremipsum package that is a dependency for the pypsum package. For some reason, in the setup.py file of loremipsum, the author includes specific requirements for the distribute package:

egg = {
    'name': name,
    'version': module.__version__,
    'author': author,
    'author_email': email.strip('<>'),
    'url': url,
    'description': "A Lorem Ipsum text generator",
    'long_description': long_description,
    'classifiers': module.__classifiers__,
    'keywords': ['lorem', 'ipsum', 'text', 'generator'],
    'setup_requires': ['distribute'],
    'install_requires': ['distribute'],
    'packages': [name],
    # 'package_dir': {'': '.'},
    # 'package_data': {'': 'default/*.txt'},
    # 'data_files': [(name, ('default/dictionary.txt', 'default/sample.txt'))],
    'include_package_data': True,
    'test_suite': 'tests.suite' }

distribute, as you may know, is a fork of the setuptools package; there's a long history behind this. Since distribute is supposed to be an almost plug-compatible replacement for setuptools, it will try to masquerade as setuptools and disable any existing setuptools already installed in that Python instance. Thus, putting distribute in a setup.py file as a requirement is usually not a good idea. By default, virtualenv will install a version of setuptools but it does have an option to use distribute instead. The Apple-supplied system Pythons in OS X 10.6 and 10.7 already come with versions of setuptools pre-installed and, because they are in non-standard system directories, cannot be so easily patched around. A simple workaround when using virtualenv on OS X seems to be to also use its no-site-packages option which will prevent the setuptools version from the system Python interfering with the required distribute in the virtualenv. No doubt the confusion between distribute and setuptools is causing the problems seen with pkg_resources since it is also supplied by both of them.

So try re-creating your virtualenv this way:

virtualenv --distribute --no-site-packages /path/to/ve

That will also have the side-effect of not including the third-party packages that Apple ships with the system Python. You can add them back in with PYTHONPATH if you really need them but it's probably better to install separate versions.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!