我有一个Python包,它的setup.py通过通常的方式在install_requires=中声明了依赖关系……其中的一个包,scikits.timeseries,有一个setup.py,期望已经安装了numpy,因此,我想先安装numpy。对于这种情况,通常情况下,依赖项安装的顺序可以控制吗?多么?
目前,setup.py下拉依赖项(如arg install_requires中所列)的顺序看起来几乎是随机的。此外,在setup.py设置中(...)我尝试使用arg:
extras_require={'scikits.timeseries': ['numpy']}
...without成功,安装依赖项的顺序不受影响。
我还尝试设置了一个pip需求文件,但同样,pip安装依赖项的顺序与需求文件的行顺序不匹配,所以不走运。
另一种可能是在靠近setup.py顶部的位置进行系统调用,以便在安装之前安装numpy (...)打电话,但我希望有更好的方法。提前感谢您的帮助。
发布于 2011-02-15 23:17:17
如果scikits.timeseries
需要numpy
,那么它应该将其声明为依赖项。如果是这样的话,pip
会帮你处理事情(我很确定setuptools
也会这样做,但我已经很久没用过它了)。如果你控制了scikits.timeseries
,那么你应该修复它的依赖声明。
发布于 2016-07-16 00:02:40
使用setup_requires
参数,例如安装numpy
之前的scipy
,将其放入setup_requires中,并添加__builtins__.__NUMPY_SETUP__ = False
钩子以正确安装numpy:
setup(
name='test',
version='0.1',
setup_requires=['numpy'],
install_requires=['scipy']
)
def run(self):
__builtins__.__NUMPY_SETUP__ = False
import numpy
发布于 2019-01-20 00:53:35
这是一个实际有效的解决方案。这不是一种必须求助于的过于“愉快”的方法,而是“绝望的时刻……”。
基本上,你必须:
安装命令覆盖setuptools "install
这样做的缺点是:
必须安装
setup.py
。代码:
from setuptools import setup
# Override standard setuptools commands.
# Enforce the order of dependency installation.
#-------------------------------------------------
PREREQS = [ "ORDERED-INSTALL-PACKAGE" ]
from setuptools.command.install import install
from setuptools.command.develop import develop
from setuptools.command.egg_info import egg_info
def requires( packages ):
from os import system
from sys import executable as PYTHON_PATH
from pkg_resources import require
require( "pip" )
CMD_TMPLT = '"' + PYTHON_PATH + '" -m pip install %s'
for pkg in packages: system( CMD_TMPLT % (pkg,) )
class OrderedInstall( install ):
def run( self ):
requires( PREREQS )
install.run( self )
class OrderedDevelop( develop ):
def run( self ):
requires( PREREQS )
develop.run( self )
class OrderedEggInfo( egg_info ):
def run( self ):
requires( PREREQS )
egg_info.run( self )
CMD_CLASSES = {
"install" : OrderedInstall
, "develop" : OrderedDevelop
, "egg_info": OrderedEggInfo
}
#-------------------------------------------------
setup (
...
install_requires = [ "UNORDERED-INSTALL-PACKAGE" ],
cmdclass = CMD_CLASSES
)
https://stackoverflow.com/questions/4996589
复制相似问题