覆盖cmdclass时将忽略python setuptools install_requires [英] python setuptools install_requires is ignored when overriding cmdclass

查看:183
本文介绍了覆盖cmdclass时将忽略python setuptools install_requires的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的setup.py:

I have a setup.py that looks like this:

from setuptools import setup
from subprocess import call
from setuptools.command.install import install

class MyInstall(install):
    def run(self):
        call(["pip install -r requirements.txt --no-clean"], shell=True)
        install.run(self)

setup(
    author='Attila Zseder',
    version='0.1',
    name='entity_extractor',
    packages=['...'],
    install_requires=['DAWG', 'mrjob', 'cchardet'],
    package_dir={'': 'modules'},
    scripts=['...'],
    cmdclass={'install': MyInstall},
)

我需要MyInstall,因为我想从github安装一些库,并且我不想使用dependency_links选项,因为不鼓励这样做(例如

I need MyInstall because I want to install some libraries from github and I didn't want to use dependency_links option, because it's discouraged (for example here), so I can do this with requirements.txt.

当我使用pip安装此软件包时,一切正常,但是由于某些原因,我必须以与纯python setup.py install一起使用的方式来解决此问题.而且不是.

When I install this package with pip, everything is working fine, but for some reasons I have to solve this in a way that it also works with pure python setup.py install. And it doesn't.

当用我自己的类覆盖setup()中的cmdclass时,install_requires似乎被忽略了.一旦我注释掉那行,就会安装那些软件包.

When overriding cmdclass in setup() with my own class, install_requires seems to be ignored. As soon as I comment out that line, those packages are being installed.

我知道distutils中不支持install_requires(如果我记得很好),但是setuptools中不支持.然后cmdclass不会对install_requires产生任何影响.

I know that install_requires is not supported for example in distutils (if I remember well), but it is in setuptools. And then cmdclass wouldn't have any effect on install_requires.

我用几个小时的时间搜索了这个问题,在stackoverflow上找到了很多相关的答案,但不是针对这个特定问题.

I googled this problem for hours, found a lot of kind of related answers on stackoverflow, but not for this particular problem.

将所有需要的软件包放入requirements.txt,一切正常,但是我想了解为什么会这样.谢谢!

With putting every needed package to requirements.txt, everything's working fine, but I would like to understand why this is happening. Thanks!

推荐答案

我也遇到了同样的问题.似乎以某种方式触发了setuptools对distutils进行旧式安装",但实际上不支持install_requires.

The same problem just happened to me. It somehow seems like something triggers setuptools to do an 'old-style install' with distutils, which indeed does not support install_requires.

您在setuptools/setuptools/command/install.py,第51-74行中调用install.run(self)

You call install.run(self) which calls run(self) in setuptools/setuptools/command/install.py, line 51-74

https://bitbucket.org/pypa/setuptools/src/8e8c50925f18eafb7e66fe020aa91a85b9a4b122/setuptools/command/install.py?at=default

def run(self):
    # Explicit request for old-style install?  Just do it
    if self.old_and_unmanageable or self.single_version_externally_managed:
        return _install.run(self)

    # Attempt to detect whether we were called from setup() or by another
    # command.  If we were called by setup(), our caller will be the
    # 'run_command' method in 'distutils.dist', and *its* caller will be
    # the 'run_commands' method.  If we were called any other way, our
    # immediate caller *might* be 'run_command', but it won't have been
    # called by 'run_commands'.  This is slightly kludgy, but seems to
    # work.
    #
    caller = sys._getframe(2)
    caller_module = caller.f_globals.get('__name__','')
    caller_name = caller.f_code.co_name

    if caller_module != 'distutils.dist' or caller_name!='run_commands':
        # We weren't called from the command line or setup(), so we
        # should run in backward-compatibility mode to support bdist_*
        # commands.
        _install.run(self)
    else:
        self.do_egg_install()

我不确定这种行为是否有意,但是要替换

I'm not sure whether this behaviour is intended, but replacing

install.run(self)

install.do_egg_install()

应该可以解决您的问题.至少它对我有用,但是我也希望得到更详细的答案.谢谢!

should solve your problem. At least it works for me, but I would also appreciate a more detailed answer. Thanks!

这篇关于覆盖cmdclass时将忽略python setuptools install_requires的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆