是否有标准方法来创建 Debian 软件包来分发 Python 程序?
关于如何做到这一点有大量信息,但由于“给猫剥皮的方法不止一种”,并且所有涵盖部分过程的教程/手册似乎都使某些与其他教程不同的假设,我仍然没有掌握它。
到目前为止,这就是我想我所理解的。
- 我的最终目标应该是创建一个“二进制”.deb 包。此类包将与平台无关(32/64 位),因为所有 Python 程序都是如此。
- 要创建“二进制”包,我首先需要创建一个源包。
- 要创建源包,我可以使用
CDBS
或debhelper
。 Debhelper 是初学者推荐的方式。 - 创建源码包的核心是用许多文件填充源目录中的 DEBIAN 目录,明确文件需要复制到哪里、它们受什么版权和许可方案、它们有什么依赖关系等等...
- 如果 Python 源代码还附带了 distutils 的 setup.py 脚本,那么第 4 步可以在很大程度上通过 dh_make 命令实现自动化。
现在我的问题是:
- 我对流程的理解是否正确?我是否遗漏了什么,或者有什么错误?
- 步骤#5对我来说确实更令人困惑:具体来说,对我来说最模糊的两点是:
- 如何编写安装独立程序的
setup.py
脚本? 编辑:由独立程序< /em> 我的意思是一个供桌面用户使用的程序(而不是一个模块,我将其理解为导入后由其他软件使用的功能集合)。在我的具体情况下,我实际上需要两个这样的“程序”:主软件和一个单独的实用程序(实际上是第二个“程序”,它应该与另一个程序位于同一个包中)。< /里> - DEB 包的此类脚本有什么特殊性?官方文档似乎只处理 RPM 和 Windows 内容...
- 如何编写安装独立程序的
顺便说一句:这些是迄今为止我能找到的最好的信息来源。如果你还有比这更好的,请分享! :)
- Ubuntu 的 Python 打包指南
- 从 python 创建 .deb 包setup.py(它显示这些步骤,但它解释不足以让我遵循)
- ShowMeDo 视频“从 python 创建 .deb 包” 程序”(它似乎不是最新的,并且 - 如果我做对了 - 将生成供个人使用的包,没有依赖项 并且没有签名的变更日志和其他关键数据,这将使其与 Debian 政策不兼容)。
There is a ton of information on how to do this, but since "there is more than one way to skin a cat", and all the tutorials/manuals that cover a bit of the process seem to make certain assumptions which are different from other tutorials, I still didn't manage to grasp it.
So far this is what I think I understood.
- My final goal should be that of creating a "binary" .deb package. Such package will be platform-independent (32/64 bit) as all Python programs are such.
- To create a "binary" package I need first to create a source package.
- To create the source package I can use either
CDBS
ordebhelper
. Debhelper is the recommended way for beginners. - The core of creating a source package is populating the
DEBIAN
directory in the source directory with a number of files clarifying where files need to be copied, what copyright and licensing scheme they are subject to, what dependencies they have, etc... - Step #4 can be largely automated the
dh_make
command if the Python source also comes with a distutils'setup.py
script.
Now my questions:
- Is my understanding of the process correct? Is there anything I am missing, or anything that I got wrong?
- Step #5 is really the more confusing to me: specifically the two points that remains most obscure to me are:
- How do I write a
setup.py
script that install a stand-alone programme? EDIT: By standalone programme I mean a program intended to be used by a desktop user (as opposed to a module which I understand like a collection of functionality to be used by other software after having been imported). In my specific case I would actually need two such "programs": the main software and a separate utility (in effect a second "program" that should be in the same package with the other one). - What are the specificities of such a script for DEB packages? The official documentation only seems to deal with RPM and Windows stuff...
- How do I write a
BTW: These are the best sources of information that I could find myself so far. If you have anything better than this, please share! :)
- Ubuntu's Python packaging guide
- Creating a .deb package from a python setup.py (it shows the steps, but it doesn't explain them enough for me to follow along)
- ShowMeDo video on "creating a .deb package out of a python
program" (it doesn't seem up-to-date and - if I got it right - will produce packages for personal use, without dependencies
and without a signed changelog and other key data that will make it incompatible with the Debian policy).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来 stdeb 会做你想要的。
另外,为了安装脚本,我强烈建议 分发 console_scripts入口点支持。
It looks like stdeb will do what you want.
Also, for installing scripts, I strongly recommend distribute's console_scripts entry point support.
构建 deb 包的正确方法是使用 dpkg-buildpackage,但有时有点复杂。相反,您可以使用 dpkg -b,它将创建您的 Debian 软件包。
这些是使用
dpkg -b
使用任何二进制文件或任何类型的无需手动编译即可自动运行的脚本(Python、Bash、Perl 和 Ruby)创建 Debian 软件包的基础知识:创建文件和文件夹以重新创建以下结构:
放置在
/usr/bin/
的脚本是直接从终端调用的,请注意,我没有为脚本添加扩展名。您还可以注意到,deb 包的结构将是安装后程序的结构。所以如果你按照这个逻辑,如果你的程序只有一个文件,你可以直接把它放在ProgramName-Version/usr/bin/your_script
下,但如果你有多个文件,你应该把它们放在 < code>ProgramName-Version/usr/share/ProgramName/all your files 并在/usr/bin/
下仅放置一个文件,该文件将从/usr/share 调用您的脚本/程序名称/
更改所有root 文件夹权限:
更改脚本的权限:
最后,您可以运行:
dpkg -b /path/to/the/ProgramName-Version
,您的 deb 包将被创建! (您还可以添加后/预安装脚本和您想要的一切,它的工作方式就像普通的 Debian 软件包)以下是
control
文件的示例。您只需将其复制粘贴到名为“control”的空文件中,然后将其放入 DEBIAN 文件夹中。有关 Debian 软件包的完整文章可以在此处阅读。
The right way of building a deb package is using
dpkg-buildpackage
, but sometimes it is a little bit complicated. Instead you can usedpkg -b <folder>
, and it will create your Debian package.These are the basics for creating a Debian package with
dpkg -b <folder>
with any binary or with any kind of script that runs automatically without needing manual compilation (Python, Bash, Perl, and Ruby):Create the files and folders in order to recreate the following structure:
The scripts placed at
/usr/bin/
are directly called from the terminal, note that I didn't add an extension to the script. Also you can notice that the structure of the deb package will be the structure of the program once it's installed. So if you follow this logic if your program has a single file, you can directly place it underProgramName-Version/usr/bin/your_script
, but if you have multiple files, you should place them underProgramName-Version/usr/share/ProgramName/all your files
and place only one file under/usr/bin/
that will call your scripts from/usr/share/ProgramName/
Change all the folder permission to root:
Change the script's permissions:
Finally, you can run:
dpkg -b /path/to/the/ProgramName-Version
and your deb package will be created! (You can also add the post/pre inst scripts and everything you want, it works like a normal Debian package)Here is an example of the
control
file. You only need to copy-paste it in to an empty file called "control" and put it in the DEBIAN folder.The full article about Debian packages can be read here.
Barry Warsaw 的这篇文章 提供了帮助我在这个过程中走得很远。不过,我仍然需要进行大量搜索,并且我阅读了大部分 Ubuntu 包装指导过去的某个时间。
拥有一个好的
setup.py
是一个非常好的建议。我发现这两本指南非常好:This article by Barry Warsaw helped me in getting quite far through the process. I still had to do a lot of searching on the side, though, and I read most of the Ubuntu packaging guide some time in the past.
Having a good
setup.py
is a really good advice. I found these two guides quite good:有几个库可以抽象出所有必要的步骤,让您使用单个命令将 Python 包转换为 Debian 包。
假设你的Python包已经有
setup.py
,在setup.py
所在的目录中,你可以使用:stdeb (已在此 答案,使用
pip install stdeb
安装)。要创建 Debian 软件包,请运行:输出
.deb
文件将位于bdist_deb
目录中。fpm (使用
gem install --no-ri --no-rdoc 进行安装fpm
)。要创建 Debian 软件包,请运行:py2deb (使用
pip install py2deb< /代码>)。要创建 Debian 软件包,请运行:
<前><代码>py2deb -r 。 。
每个库都有其自己的注意事项,因此您可能想尝试最适合您的库。
There are several libraries out there which abstract away all the necessary steps and let you transform your Python package into a Debian package with a single command.
Assuming your python package already has the
setup.py
, in the directory wheresetup.py
is located, you could use:stdeb (Already mentioned in this answer, install with
pip install stdeb
). To create a Debian package, run:The output
.deb
file will be located in thebdist_deb
directory.fpm (install with
gem install --no-ri --no-rdoc fpm
). To create a Debian package, run:py2deb (install with
pip install py2deb
). To create a Debian package, run:Each of these libraries has its own caveats, so you might want to try what works best for you.
这个方法对我有用。
安装标准数据库。 (pip install stdeb)
创建 setup.py。我正在使用 PyCharm。这将 (https://www.jetbrains.com /help/pycharm/creating-and-running-setup-py.html)
将这些命令写入您的项目目录。
This method works for me.
install stdeb. (pip install stdeb)
create setup.py. I'm using PyCharm. This will (https://www.jetbrains.com/help/pycharm/creating-and-running-setup-py.html)
write these commands in your project directory.