简体   繁体   English

Python导入错误,自动安装

[英]Python Import error , auto install

I wonder, if the required python library to be imported is not yet installed , and you need to import it , is there any way that can auto-install it if the library doesn't exists. 我想知道,是否尚未安装所需的要导入的python库,而您需要将其导入,如果该库不存在,是否有任何方法可以自动安装它。

My python scripts often include custom libraries that are not installed by default , and those scripts land on different machines with python installed but not the custom libraries , so i want a way such that the required library gets installed automatically if import doesn't succeed. 我的python脚本通常包含默认情况下未安装的自定义库,并且这些脚本在安装了python的不同计算机上运行,​​但未安装自定义库,因此我想要一种方法,以便在导入不成功时自动安装所需的库。

More specifically , there is a Jenkins job that can run the script on any of the 500 slaves , and i don't have to install custom libs on each of them , instead on the slave where the job lands automatically , the custom lib should be installed if there is some import error. 更具体地说,有一个Jenkins作业可以在500个从属中的任何一个上运行脚本,而我不必在每个从属上安装自定义库,而是在作业自动进入的从属上安装自定义库,自定义库应为如果出现某些导入错误,请安装。

Common practice is to list libraries you use in requirements.txt file. 常见的做法是列出您在requirements.txt文件中使用的库。 Then users of your script will be able to install all the dependencies via one command. 然后,脚本用户可以通过一个命令安装所有依赖项。

You can try to use pyinstaller and provide a ready to use package (eg exe file on Windows) to your customers. 您可以尝试使用pyinstaller并向您的客户提供即用型软件包(例如Windows上的exe文件)。 So even if the other computer has no internet access to download missing packages, your script will work. 因此,即使另一台计算机没有互联网可下载丢失的软件包,您的脚本也可以使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM