是否有标准方法来创建 Debian 软件包来分发 Python 程序?

发布于 2024-11-30 01:37:59 字数 1583 浏览 1 评论 0原文

关于如何做到这一点有大量信息,但由于“给猫剥皮的方法不止一种”,并且所有涵盖部分过程的教程/手册似乎都使某些与其他教程不同的假设,我仍然没有掌握它。

到目前为止,这就是我想我所理解的。

  1. 我的最终目标应该是创建一个“二进制”.deb 包。此类包将与平台无关(32/64 位),因为所有 Python 程序都是如此。
  2. 要创建“二进制”包,我首先需要创建一个源包。
  3. 要创建源包,我可以使用 CDBSdebhelper。 Debhelper 是初学者推荐的方式。
  4. 创建源码包的核心是用许多文件填充源目录中的 DEBIAN 目录,明确文件需要复制到哪里、它们受什么版权和许可方案、它们有什么依赖关系等等...
  5. 如果 Python 源代码还附带了 distutils 的 setup.py 脚本,那么第 4 步可以在很大程度上通过 dh_make 命令实现自动化。

现在我的问题是:

  1. 我对流程的理解是否正确?我是否遗漏了什么,或者有什么错误?
  2. 步骤#5对我来说确实更令人困惑:具体来说,对我来说最模糊的两点是:
    • 如何编写安装独立程序的 setup.py 脚本? 编辑:独立程序< /em> 我的意思是一个供桌面用户使用的程序(而不是一个模块,我将其理解为导入后由其他软件使用的功能集合)。在我的具体情况下,我实际上需要两个这样的“程序”:主软件和一个单独的实用程序(实际上是第二个“程序”,它应该与另一个程序位于同一个包中)。< /里>
    • DEB 包的此类脚本有什么特殊性?官方文档似乎只处理 RPM 和 Windows 内容...

顺便说一句:这些是迄今为止我能找到的最好的信息来源。如果你还有比这更好的,请分享! :)

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.

  1. 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.
  2. To create a "binary" package I need first to create a source package.
  3. To create the source package I can use either CDBS or debhelper. Debhelper is the recommended way for beginners.
  4. 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...
  5. Step #4 can be largely automated the dh_makecommand if the Python source also comes with a distutils' setup.py script.

Now my questions:

  1. Is my understanding of the process correct? Is there anything I am missing, or anything that I got wrong?
  2. 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...

BTW: These are the best sources of information that I could find myself so far. If you have anything better than this, please share! :)

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

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

发布评论

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

评论(5

戏舞 2024-12-07 01:37:59

看起来 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.

樱娆 2024-12-07 01:37:59

构建 deb 包的正确方法是使用 dpkg-buildpackage,但有时有点复杂。相反,您可以使用 dpkg -b,它将创建您的 Debian 软件包。

这些是使用 dpkg -b 使用任何二进制文件或任何类型的无需手动编译即可自动运行的脚本(Python、Bash、Perl 和 Ruby)创建 Debian 软件包的基础知识:

  1. 创建文件和文件夹以重新创建以下结构:

     ProgramName-Version/
     程序名称-版本/DEBIAN
     程序名称-版本/DEBIAN/control
     程序名称-版本/usr/
     程序名-版本/usr/bin/
     程序名称-版本/usr/bin/your_script
    

    放置在/usr/bin/的脚本是直接从终端调用的,请注意,我没有为脚本添加扩展名。您还可以注意到,deb 包的结构将是安装后程序的结构。所以如果你按照这个逻辑,如果你的程序只有一个文件,你可以直接把它放在 ProgramName-Version/usr/bin/your_script 下,但如果你有多个文件,你应该把它们放在 < code>ProgramName-Version/usr/share/ProgramName/all your files 并在 /usr/bin/ 下仅放置一个文件,该文件将从 /usr/share 调用您的脚本/程序名称/

  2. 更改所有root 文件夹权限:

     chown root:root -R /path/to/ProgramName-Version
    
  3. 更改脚本的权限:

     chmod 0755 /path/to/the/script
    
  4. 最后,您可以运行:dpkg -b /path/to/the/ProgramName-Version,您的 deb 包将被创建! (您还可以添加后/预安装脚本和您想要的一切,它的工作方式就像普通的 Debian 软件包)


以下是 control 文件的示例。您只需将其复制粘贴到名为“control”的空文件中,然后将其放入 DEBIAN 文件夹中。

Package: ProgramName
Version: VERSION
Architecture: all
Maintainer: YOUR NAME <EMAIL>
Depends: python2.7, etc , etc,
Installed-Size: in_kb
Homepage: http://example.com
Description: Here you can put a one line description. This is the short Description.
 Here you put the long description, indented by one space.

有关 Debian 软件包的完整文章可以在此处阅读。

The right way of building a deb package is using dpkg-buildpackage, but sometimes it is a little bit complicated. Instead you can use dpkg -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):

  1. Create the files and folders in order to recreate the following structure:

     ProgramName-Version/
     ProgramName-Version/DEBIAN
     ProgramName-Version/DEBIAN/control
     ProgramName-Version/usr/
     ProgramName-Version/usr/bin/
     ProgramName-Version/usr/bin/your_script
    

    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 under ProgramName-Version/usr/bin/your_script, but if you have multiple files, you should place them under ProgramName-Version/usr/share/ProgramName/all your files and place only one file under /usr/bin/ that will call your scripts from /usr/share/ProgramName/

  2. Change all the folder permission to root:

     chown root:root -R /path/to/ProgramName-Version
    
  3. Change the script's permissions:

     chmod 0755 /path/to/the/script
    
  4. 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.

Package: ProgramName
Version: VERSION
Architecture: all
Maintainer: YOUR NAME <EMAIL>
Depends: python2.7, etc , etc,
Installed-Size: in_kb
Homepage: http://example.com
Description: Here you can put a one line description. This is the short Description.
 Here you put the long description, indented by one space.

The full article about Debian packages can be read here.

记忆で 2024-12-07 01:37:59

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:

漆黑的白昼 2024-12-07 01:37:59

有几个库可以抽象出所有必要的步骤,让您使用单个命令将 Python 包转换为 Debian 包。

假设你的Python包已经有setup.py,在setup.py所在的目录中,你可以使用:

  • stdeb (已在此 答案,使用 pip install stdeb 安装)。要创建 Debian 软件包,请运行:

    python setup.py --command-packages=stdeb.command bdist_deb
    

    输出 .deb 文件将位于 bdist_deb 目录中。

  • fpm (使用 gem install --no-ri --no-rdoc 进行安装fpm)。要创建 Debian 软件包,请运行:

    fpm -s python -t deb setup.py
    
  • 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 where setup.py is located, you could use:

  • stdeb (Already mentioned in this answer, install with pip install stdeb). To create a Debian package, run:

    python setup.py --command-packages=stdeb.command bdist_deb
    

    The output .deb file will be located in the bdist_deb directory.

  • fpm (install with gem install --no-ri --no-rdoc fpm). To create a Debian package, run:

    fpm -s python -t deb setup.py
    
  • py2deb (install with pip install py2deb). To create a Debian package, run:

    py2deb -r . .
    

Each of these libraries has its own caveats, so you might want to try what works best for you.

可爱暴击 2024-12-07 01:37:59

这个方法对我有用。

  1. 安装标准数据库。 (pip install stdeb)

  2. 创建 setup.py。我正在使用 PyCharm。这将 (https://www.jetbrains.com /help/pycharm/creating-and-running-setup-py.html)
    将这些命令写入您的项目目录。

  3. sudo apt-get install python3-stdeb fakeroot python-all
  4. python3 setup.py sdist
  5. sudo python3 setup.py --command-packages=stdeb.command bdist_deb
  6. 您的 deb 文件位于项目中的 deb_dist 目录中

This method works for me.

  1. install stdeb. (pip install stdeb)

  2. 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.

  3. sudo apt-get install python3-stdeb fakeroot python-all
  4. python3 setup.py sdist
  5. sudo python3 setup.py --command-packages=stdeb.command bdist_deb
  6. your deb file is in the deb_dist directory that is in your project
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文