在一个捆绑包中轻松部署 Python 和应用程序,适用于 Linux

发布于 2024-11-24 16:55:24 字数 482 浏览 3 评论 0原文

我在服务器端开发相当大的Python应用程序,包括所有数据库连接、文件提取、解析、命令行调用。

由于我使用了标准 python 库之外的许多第三方模块,因此这成为部署的噩梦。我失去了他们的踪迹。特别是不同的 Linux 操作系统使用不同的版本,因此不再适合使用操作系统的包管理器安装它们。

我想将它们部署在所有一个包中,包括我正在使用的当前 python 版本(大多数操作系统仍然附带 Python 2.5,6 我正在使用 2.7 和 2.7 的特定功能。)。

此外,我必须教客户如何部署,以便他们可以在其他服务器上进行测试。但他们并不是 Linux 专家。我必须让它变得简单,在一个脚本中或通过复制和粘贴。

Windows 有 Portablepython,但 Linux 没有。我从来没有使用过 python 打包,因为我通常在我只托管的服务器上工作。

请告诉我 python 的可用打包和部署选项,其中包括所有已安装的 python 模块和 python 本身。

I Develop Fairly large python application on server side , with all database connect , files extraction , parsing , command line calls.

It becomes a nightmare for deploying as i used many third party modules outside of standard python lib. And i lost track of them . Especially Differnt Linux OS uses different version of them so it is no longer good to install them using OS's package manager.

I want to deploy them in all one bundle including current python version i am using (Most OS Still ship with Python 2.5,6 i am using 2.7 and 2.7 specific features.) .

Further more , i have to teach the client to how to deploy , so they can test out in other servers. But they are not linux experts . I have to make it easy , in one script or by doing copy and paste.

There is Portablepython for Windows But there's nothing for Linux. And i had never used python Packaging as i usually work on server that i only host.

Please enlighten me of avaliable packaging and deployment options for python , that includes all the installed python modules and python itself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦一生花开无言 2024-12-01 16:55:24

大多数 Python 包可以通过在部署中创建 lib 或类似目录,并将其添加到 Python 中的 sys.pathPYTHONPATH 来部署。外部,然后将包目录(通常在您解压缩的目录内)复制到该目录中。这使您可以将包与部署的代码一起保存在 Mercurial 存储库中。

部署Python本身会比较麻烦,但如果你可以控制它的安装位置(例如/usr/local/opt),那么它只是一个./configure --prefix=...makesudo make install 的问题。然后,只要脚本被标记为可执行,您就可以通过以类似 #!/usr/local/bin/python 的行开头来将脚本指向该 Python。

例如,如果您正在部署需要 docutils 的代码,那么您需要执行以下操作:

cd projectDir
mkdir -p lib
tar xzvf ~/Downloads/docutils-0.8.tgz
mv docutils-0.8/docutils lib
rm -r docutils-0.8

然后此目录中的 Python 模块将仅在开头添加以下内容:

#!/usr/local/bin/python

import os
import sys
sys.path(os.path.join(os.path.dirname(sys.argv[0]), "lib"))
import docutils

Most Python packages can be deployed by creating a lib or similar directory in your deployment, and adding it to sys.path in Python, or PYTHONPATH outside, then copying the package directory (usually inside the directory you unzipped) into that directory. This lets you keep the package with your deployed code, say, in a Mercurial repository.

Deploying Python itself is going to be a bit more hassle, but if you can control where it's installed (such as /usr/local or /opt), then it's just a matter of ./configure --prefix=..., make, and sudo make install. Then you can point your scripts to that Python by starting them with a line like #!/usr/local/bin/python, as long as the script is marked executable.

For example, if you were deploying code that needs docutils, then you'd do something like:

cd projectDir
mkdir -p lib
tar xzvf ~/Downloads/docutils-0.8.tgz
mv docutils-0.8/docutils lib
rm -r docutils-0.8

Then a Python module in this directory would just add the following at the start:

#!/usr/local/bin/python

import os
import sys
sys.path(os.path.join(os.path.dirname(sys.argv[0]), "lib"))
import docutils
落花浅忆 2024-12-01 16:55:24

这是一个广泛的主题,但这里有一些提示。

对于您的 Python 项目及其依赖项,请查看 virtualenvpip

Virtualenv 在您的目标平台上提供了一个隔离的 python 环境,然后您可以将项目安装到其中。

Pip 是一个软件包安装工具,它将下载并安装您的软件包及其依赖项。查看 pip freeze ,它提供了一种快速方法来定义当前已安装在开发环境中的依赖项列表。

如果您想了解有关 Python 中的包分发的更多信息,那么您还应该阅读 distribute 项目。

对于系统的非python组件,包括安装python本身,可以使用像Puppet这样的系统自动化工具,但听起来这对于您的需求来说可能有点过分了。如果您正在寻找一步安装,您可能应该考虑为目标系统的软件包构建一个软件包经理。

This is a broad topic, but here are some pointers.

For your Python project and it's dependencies, have a look at virtualenv, and pip.

Virtualenv provides an isolated python environment on your target platform that you can then install your project into.

Pip is a package installation tool that will download and install your package and its the dependencies. Have a look at pip freeze to provide a quick way of defining a list of dependencies that you currently have installed in your development environment.

If you want to learn more about package distribution in Python then you should also read up about the distribute project.

For the non-python components of the system, including installing python itself, a system automation tool like Puppet can be used, but sounds like it might be overkill for your needs. If you are looking for a one-step installation, you should probably be looking into building a package for your target system's package manager.

骄傲 2024-12-01 16:55:24

我想将它们部署在所有一个模块中,包括我正在使用的当前 python 版本(大多数操作系统仍然附带 Python 2.5,6 我正在使用 2.7 和 2.7 的特定功能。)。

也许 VirtualEnv 就是您所需要的?

I want to deploy them in all one module including current python version i am using (Most OS Still ship with Python 2.5,6 i am using 2.7 and 2.7 specific features.) .

May be VirtualEnv is what you need for this?

Spring初心 2024-12-01 16:55:24

没有理由进行超级简单的服务器端设置。

不要在这上面浪费时间。

将安装多少服务器?不多。

系统管理员期望基于服务器的应用程序具有一定程度的复杂性。

您有一个 3rd 方软件包列表;他们按照该列表进行安装。

然后,在完成所有安装后,他们会安装并配置您的软件包。

这是许多从事服务器工作的系统管理员所期望的。他们期望依赖项并且期望多步骤安装。

There's no reason for Super Simple Server Side Setup.

Don't waste time on that.

How many server installations will happen? Not many.

Sys admins expect a certain level of complexity in server-based applications.

You have a list of 3rd party packages; they follow that list and do the installs.

Then -- after they've done all the installs -- they install and configure your package.

That's what many sys admins who work on servers expect. They expect dependencies and they expect a multi-step install.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文