我有一个setup.py看起来像这样:
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_linksoption,因为不鼓励使用它(例如here),所以我可以使用requirements.txt做到这一点。
MyInstall
dependency_links
当我使用来安装此软件包时pip,一切都工作正常,但是由于某些原因,我必须以与pure一起使用的方式来解决此问题python setup.py install。事实并非如此。
pip
python setup.py install
当用我自己的类重写cmdclass时setup(),install_requires似乎被忽略了。我注释掉该行后,即会安装那些软件包。
cmdclass
setup()
install_requires
我知道distutils中不支持install_requires(如果我记得很好),但是setuptools中不支持。然后cmdclass不会对产生任何影响install_requires。
我用几个小时搜索了这个问题,在stackoverflow上找到了很多相关的答案,但是对于这个特定的问题却没有。
通过将每个需要的包放到requirements.txt,一切正常,但是我想了解为什么会这样。谢谢!
我也遇到了同样的问题。似乎以某种方式触发setuptools进行“旧式安装” distutils,但确实不支持install_requires。
distutils
您可以在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()
应该可以解决您的问题。至少它对我有用,但是我也希望得到更详细的答案。谢谢!