Migration from distribute to setuptools

对着背影说爱祢 提交于 2019-12-08 10:08:55

问题


I'm trying to convert a project that I had installing fine with distribute over to a newer setuptools based installer. For some reason I can't get setuptools to run at all. When I run my setup.py I get errors from distutils about unsupported options which are all the extension options provided by setuptools. I can't figure out why setuptools isn't taking care of these correctly. This is on a Debian Wheezy system running Python 2.7.

I created a simple test case to demonstrate the problem. It is a standalone script that I want installed as a utility with an executable wrapper script:

foo.py

#!/usr/bin/python
def main():
  print 'Foo main() ran'

if __name__ == '__main__':
  main()

setup.py

from setuptools import setup

setup(name='foo',
    version='1.0',
    py_modules = ['foo'],
    entry_points = {
        'console_scripts': ['foo = foo:main'] # setuptools extension
    },
    include_package_data = True # another setuptools extension
)

The version of setuptools in the Debian package archive is 0.6.24 which predates the merger with distribute and I would prefer to use something that retains some of the distribute heritage. I've been installing various versions of setuptools with pip. The latest 4.0.1 won't install properly but most anything from 1.4 to 3.8 works:

$ sudo pip install setuptools==3.8
...
$ python
Python 2.7.3 (default, Mar 13 2014, 11:03:55) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from setuptools import version
>>> version.__version__
'3.8'

The setuptools package/egg is placed in /usr/local/lib/python2.7/dist-packages which is normal on a Debian system when using pip.

When I try to install with my setup.py I get the following errors:

$ sudo python setup.py install
/usr/lib/python2.7/distutils/dist.py:267:
    UserWarning: Unknown distribution option: 'entry_points'
  warnings.warn(msg)
/usr/lib/python2.7/distutils/dist.py:267:
    UserWarning: Unknown distribution option: 'include_package_data'
  warnings.warn(msg)
running install
running build
running build_py
running install_lib
running install_egg_info
Removing /usr/local/lib/python2.7/dist-packages/foo-1.0.egg-info
Writing /usr/local/lib/python2.7/dist-packages/foo-1.0.egg-info

Distutils installs foo.py to /usr/local/lib/python2.7/dist-packages/ but obviously the setuptools generated wrapper script is absent. I would have expected setuptools to do its subclassing/monkeypatching thing to take care of anything not supported by distutils.

I remember setuptools being cranky years ago which is why I settled on using distribute. It's disappointing that it still doesn't "just work". Is there anything obvious that I'm missing? I have a suspicion that this has something to do with Debian's use of the dist-packages directory in place of site-packages but that was never an issue with distribute.


回答1:


Well it looks like the problem is that setuptools doesn't like being installed into /usr/local/lib/....

I forced pip to put it into /usr/lib/... with:

sudo pip install --install-option="--prefix=/usr/lib/python2.7/dist-packages" \
  setuptools==3.8

setup.py installs cleanly after that.



来源:https://stackoverflow.com/questions/24050576/migration-from-distribute-to-setuptools

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