将 python 脚本和依赖项捆绑到一个文件中 [英] Bundle python script and dependencies into a single file

查看:68
本文介绍了将 python 脚本和依赖项捆绑到一个文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些脚本有自己的一些函数的副本,所以我将这些函数提取到一个模块中,并让脚本导入该函数.这些脚本将被复制到一堆 linux 服务器并执行.当脚本独立运行时,我只需将文件复制到服务器并执行python".

I have a few script that had their own copy of a some functions, so I extracted these functions to a module and had the scripts import the function. These script are to be copied over to a bunch of linux servers and executed. When the scripts worked standalone, I would simply copy the files over to the servers and execute "python ".

我有一个中央管理服务器,可以在不同的服务器上复制和运行脚本.

I have a central management server that will copy and run the scripts on the different servers.

我已经阅读了一些关于 python 鸡蛋的书,但可以使用一些关于方法的建议.我今天做的方法是复制并简单地运行python脚本.由于这工作正常,我在想也许有一种方法可以将脚本本身与它们所依赖的(内部)模块捆绑在一起,将捆绑包复制到服务器并执行它们.不明白为什么我需要使用pip"安装任何东西.

I've done some reading on python eggs, but could use some advice on method to go for. The way I do it today is to copy and simply run the python script. As this works fine, I was thinking maybe there is a way to bundle the scripts themselves with the (in-house) module they're dependent on, copy the bundle over to the servers and execute them. Don't see why I would need to install anything using "pip".

现在,你们会推荐什么样的设置?我应该在本地计算机上构建鸡蛋,然后让管理服务器将鸡蛋文件复制到服务器上吗?我更愿意从管理服务器复制服务器需要的所有内容,而不是让服务器自己拉下依赖项,这样我就不必在所有防火墙上打更多洞.由于鸡蛋通常需要拉低依赖关系,也许鸡蛋不是要走的路?

Now, what kind of setup would you guys recommend? Should I maybe build eggs on my local computer, and have the management server copy the egg file over to the servers? I would prefer to copy everything the server need over from the management server, instead of having the servers pull down dependencies themselves, so that I won't have to punch more holes all the firewalls. Since eggs typically need to pull down dependencies, maybe eggs are not the way to go?

我的大多数服务器都运行 python 2.6,但我确实有一些运行 python 2.4 和 3.2.

Most of my servers are running python 2.6, but I do have some running python 2.4 and 3.2.

您好,肯尼斯

推荐答案

您可能需要考虑查看 Twitter 的 PEX 库,它可以从 python 包创建可执行文件:https://pex.readthedocs.org/en/latest/whatispex.html

You might want to consider looking at Twitter's PEX library which can create executable files from python packages: https://pex.readthedocs.org/en/latest/whatispex.html

.pex 文件只是精心构造的 zip 文件,带有 #!/usr/bin/env python 和特殊的 __main.py__

.pex files are just carefully constructed zip files with a #!/usr/bin/env python and special __main.py__

这篇关于将 python 脚本和依赖项捆绑到一个文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆