如何根据需要从python脚本自动安装所需的软件包? [英] How to automatically install required packages from a python script as necessary?
问题描述
在python或linux中是否存在任何基本指示系统安装必要的东西"的东西.基本上,我发现为我工作的每个新脚本/系统/服务器安装python软件包很烦人.无论如何,每次我最终做一个sudo pip或apt-get或dnf时.为什么不在脚本本身中自动执行该操作呢?每当出现找不到软件包"错误时,请将库名称传递给install语句.这是那里吗?
Is there anything in python or linux what basically instructs the system to "install whatever is necessary". Basically I find it annoying to install python packages for each new script/system/server that I work on. Each time I end up doing a sudo pip or an apt-get or dnf anyway. Why not automate that within the script itself. Whereever a 'no package found' error crops up, pass the library name to the install statement. Is this there ?
PS:我知道docker存在,但出于纯粹的执行目的,我是在python/script级别或直接系统级别进行交谈.
PS: I know docker exists, but am talking at a python/script level or a direct system level for purely execution purposes.
谢谢
推荐答案
我知道的最好方法是,创建一个文件requirements.txt
列出其中的所有软件包名称,并使用 pip 安装它
The best way I know is, create a file requirements.txt
list out all the packages name in it and install it using pip
pip install -r requirements.txt
示例requirements.txt
:
BeautifulSoup==3.2.0
Django==1.3
Fabric==1.2.0
Jinja2==2.5.5
PyYAML==3.09
Pygments==1.4
SQLAlchemy==0.7.1
South==0.7.3
amqplib==0.6.1
anyjson==0.3
...
这篇关于如何根据需要从python脚本自动安装所需的软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!