我想创建一个通用的python脚本来启动一个python应用程序,我想安装任何依赖python模块,如果他们从目标系统中缺少。我如何从Python本身运行命令行命令'python setup.py install'的等效命令?我觉得这应该很容易,但我无法弄清楚。如何在Python中运行'python setup.py install'?
回答
import os
string = "python setup.py install"
os.system(string)
如何要做到这一点,如果setup.py是在其他路径,例如在c:\ foo \ bar \ setup.py? – Aleksandar 2012-12-03 17:02:29
可以使用subprocess模块:
import subprocess
subprocess.call(['python', 'setup.py', 'install'])
如果setup.py在其他路径上,例如在c:\ foo \ bar \ setup.py中,该怎么做? – Aleksandar 2012-12-03 17:03:38
作为第二个参数传入完整路径。 – sdolan 2012-12-03 18:04:39
我确实阅读过文档。你能给我举个例子吗? 'run_setup('/ home/ubuntu/python-augeas/setup.py',['install'])'不起作用。 – 2017-01-02 14:20:56
@AdamRyczkowski,[DISTUTILS_DEBUG](https://docs.python.org/2/distutils/setupscript.html)是你的朋友 – rstackhouse 2017-09-27 01:52:27
对于那些,谁使用的setuptools可以使用setuptools.sandbox:
from setuptools import sandbox
sandbox.run_setup('setup.py', ['clean', 'bdist_wheel'])
这对我的作品(py2.7)
我有它的setup.py一个可选的模块中的主要项目的子文件夹。
from distutils.core import run_setup [..setup(..) config of the main project..] run_setup('subfolder/setup.py', script_args=['develop',],stop_after='run')
感谢
更新:
挖了一会儿 您可以在distutils.core.run_setup
'script_name' is a file that will be run with 'execfile()'; 'sys.argv[0]' will be replaced with 'script' for the duration of the call. 'script_args' is a list of strings; if supplied, 'sys.argv[1:]' will be replaced by 'script_args' for the duration of the call.
找到那么上面的代码应和更改为
import sys
from distutils.core import run_setup
run_setup('subfolder/setup.py', script_args=sys.argv[1:],stop_after='run')
这么晚了 - 但如果有人在这里发现他/她像我一样 - 这对我有用; (python 3.4)。我的脚本是从setup.py下载的一个包。注意,你必须在setup.py上有chmod + x,我相信。
cwd = os.getcwd()
parent = os.path.dirname(cwd)
os.chdir(parent)
os.system("python setup.py sdist")
- 1. python setup.py install sudo
- 2. 在每次运行之前运行python setup.py install eclipse pydev
- 3. 在virtualenv中设置:`pip install -e .`和`python setup.py install`
- 4. 运行'python setup.py test'而不运行build_ext?
- 5. 从哪里运行python setup.py安装
- 6. Python包装:自动运行setup.py
- 7. 如何在Python中使用setup.py gammu
- 8. 如何在virtualenv中使用ansible运行python setup.py开发命令
- 9. 如何在python setup.py中运行测试套件
- 10. 'python setup.py install'和'pip install'之间的区别
- 11. Python setup.py install使用了错误的Python安装路径
- 12. xlutil install -Python
- 13. Python Setup.py
- 14. 在setup.py中执行python版本
- 15. Python中的负数extra_requires setup.py
- 16. 的Python:如何使用setup.py安装(distutil)
- 17. 使用`setup.py install`替代索引?
- 18. 如何在osx上运行Python GTK +?
- 19. 如何在setup.py中运行Makefile?
- 20. 如何从scons调用python setup.py安装?
- 21. 在python setup.py中获取错误安装
- 22. autotools和python setup.py
- 23. 的Python:如何显示在从setup.py
- 24. “pip install”和“setup.py install”中的最大递归
- 25. 我将如何运行脚本文件作为python setup.py安装的一部分?
- 26. pip install -r pip-require之间的区别VS setup.py install
- 27. MANIFEST.in忽略“python setup.py install” - 没有安装数据文件?
- 28. Python 3:setup.py:完成所有工作(build_ext + install)的pip安装
- 29. 如何在setup.py中将Python-Xlib作为依赖包含在内?
- 30. 如何在setup.py中指定显式python打包依赖关系?
相关:[?直接调用的distutils'或setuptools的设置()的命令名称/选项功能,无需解析命令行(http://stackoverflow.com/q/2850971/2127008) – Wrzlprmft 2016-04-24 18:25:14