我使用的是以下代码:
code = 'import setuptools;__file__={0!r};execfile(__file__)'.format(os.path.join(path, 'setup.py'))
args = ['install', '--single-version-externally-managed']
subprocess.check_call([sys.executable, '-c', code, args])执行setup.py并安装包。当setup.py使用distutils而不是setuptools时,就会出现这个问题:--单版本外部管理无法被distutils识别。
如何强制setup.py使用setuptools?
发布于 2011-09-10 02:40:50
你所写的基本上就是pip所做的。根据您编写的代码,您将使用setuptools的setup函数,因为您是从setuptools导入的。因此,setup.py脚本是否导入Setuptools paves over Distutils' setup function in its __init__.py.并不重要。Setuptools总是会赢的。
如果由于某些原因,您在运行命令时仍有问题。在执行之前尝试编译文件。exec(compile(...))而不是execfile(...)
作为对@jknair答案的回应...我也不鼓励使用ez_setup.py,因为它的代码重复,具有意想不到的行为,并且在包分发期间经常被排除在外(这使得像pip这样的工具很难在没有ImportError的情况下运行setup.py )。
https://stackoverflow.com/questions/6089078
复制相似问题