我有一个setup.py
看起来像这样:
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
选项,因为不鼓励使用它(例如here),因此我可以使用requirements.txt进行此操作。当我使用
pip
安装此软件包时,一切工作正常,但是由于某些原因,我必须以与纯python setup.py install
一起使用的方式解决此问题。事实并非如此。当用我自己的类覆盖
cmdclass
中的setup()
时,install_requires
似乎被忽略了。我注释掉该行后,即会安装那些软件包。我知道distutils中不支持install_requires(如果我记得很好),但是setuptools中不支持。然后
cmdclass
对install_requires
不会有任何影响。我用几个小时搜索了这个问题,在stackoverflow上找到了很多相关的答案,但是对于这个特定问题却没有。
通过将每个需要的包放到requirements.txt,一切正常,但是我想了解为什么会这样。谢谢!
最佳答案
我也遇到了同样的问题。似乎以某种方式触发了setuptools使用distutils
进行“旧式安装”,而实际上不支持install_requires
。
您可以在setuptools/setuptools/command/install.py,第51-74行中调用install.run(self),后者会调用run(self)
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()
我不确定这种行为是否有意,但是要替换
install.run(self)
和
install.do_egg_install()
应该可以解决您的问题。至少它对我有用,但是我也希望得到更详细的答案。谢谢!
关于python - 覆盖cmdclass时将忽略python setuptools install_requires,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21915469/