简体   繁体   English

有没有标准的方法来创建用于分发 Python 程序的 Debian 软件包?

[英]Is there a standard way to create Debian packages for distributing Python programs?

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.我的最终目标应该是创建一个“二进制”.deb 包。 Such package will be platform-independent (32/64 bit) as all Python programs are such.此类包将与平台无关(32/64 位),因为所有 Python 程序都是如此。
  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 .要创建源包,我可以使用CDBSdebhelper Debhelper is the recommended way for beginners. Debhelper 是初学者的推荐方式。
  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...创建源包的核心是在源目录中的DEBIAN目录中填充许多文件,这些文件阐明了文件需要复制到哪里,它们受制于什么版权和许可方案,它们具有什么依赖关系等......
  5. Step #4 can be largely automated the dh_make command if the Python source also comes with a distutils' setup.py script.如果Python 源还带有 distutils 的setup.py脚本,步骤 #4 可以在很大程度上自动化dh_make命令。

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:第 5 步对我来说真的更令人困惑:特别是对我来说最模糊的两点是:
    • How do I write a setup.py script that install a stand-alone programme?如何编写安装独立程序的setup.py脚本? 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?这种用于 DEB 包的脚本有什么特点? The official documentation only seems to deal with RPM and Windows stuff...官方文档似乎只处理 RPM 和 Windows 的东西......

BTW: These are the best sources of information that I could find myself so far.顺便说一句:这些是迄今为止我能找到的最好的信息来源。 If you have anything better than this, please share!如果你有比这更好的东西,请分享! :) :)

It looks like stdeb will do what you want.看起来stdeb会做你想做的。

Also, for installing scripts, I strongly recommend distribute's console_scripts entry point support.此外,对于安装脚本,我强烈建议分发的 console_scripts入口点支持。

This article by Barry Warsaw helped me in getting quite far through the process. Barry Warsaw 的这篇文章帮助我完成了整个过程。 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.不过,我仍然需要进行大量搜索,而且我在过去一段时间阅读了大部分Ubuntu 打包指南

Having a good setup.py is a really good advice.拥有一个好的setup.py是一个非常好的建议。 I found these two guides quite good:我发现这两个指南非常好:

The right way of building a deb package is using dpkg-buildpackage , but sometimes it is a little bit complicated.构建 deb 包的正确方法是使用dpkg-buildpackage ,但有时它有点复杂。 Instead you can use dpkg -b <folder> , and it will create your Debian package.相反,您可以使用dpkg -b <folder> ,它会创建您的 Debian 软件包。

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):这些是使用dpkg -b <folder>使用任何二进制文件或任何类型的脚本创建 Debian 软件包的基础知识,这些脚本无需手动编译(Python、Bash、Perl 和 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.放在/usr/bin/的脚本是直接从终端调用的,注意我没有给脚本添加扩展名。 Also you can notice that the structure of the deb package will be the structure of the program once it's installed.您还可以注意到 deb 包的结构将是程序安装后的结构。 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/所以如果按照这个逻辑,如果你的程序只有一个文件,你可以直接把它放在ProgramName-Version/usr/bin/your_script ,但是如果你有多个文件,你应该把它们放在ProgramName-Version/usr/share/ProgramName/all your files并仅将一个文件放在/usr/bin/ ,该文件将从/usr/share/ProgramName/调用您的脚本

  2. Change all the folder permission to root:将所有文件夹权限更改为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!最后,您可以运行: dpkg -b /path/to/the/ProgramName-Version并且您的 deb 包将被创建! (You can also add the post/pre inst scripts and everything you want, it works like a normal Debian package) (你也可以添加 post/pre inst 脚本和你想要的一切,它像一个普通的 Debian 包一样工作)


Here is an example of the control file.这是control文件的示例。 You only need to copy-paste it in to an empty file called "control" and put it in the DEBIAN folder.您只需要将其复制粘贴到一个名为“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.

The full article about Debian packages can be read here .可以在此处阅读有关 Debian 软件包的完整文章。

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.有几个库可以抽象出所有必要的步骤,让您可以使用单个命令将 Python 包转换为 Debian 包。

Assuming your python package already has the setup.py , in the directory where setup.py is located, you could use:假设你的Python包已经有了setup.py ,在目录setup.py所在,你可以使用:

  • stdeb (Already mentioned in this answer , install with pip install stdeb ). stdeb (在这个答案中已经提到,使用pip install stdeb )。 To create a Debian package, run:要创建 Debian 软件包,请运行:

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

    The output .deb file will be located in the bdist_deb directory.输出.deb文件将位于bdist_deb目录中。

  • fpm (install with gem install --no-ri --no-rdoc fpm ). fpm (使用gem install --no-ri --no-rdoc fpm )。 To create a Debian package, run:要创建 Debian 软件包,请运行:

     fpm -s python -t deb setup.py
  • py2deb (install with pip install py2deb ). py2deb (使用pip install py2deb )。 To create a Debian package, run:要创建 Debian 软件包,请运行:

     py2deb -r . .

Each of these libraries has its own caveats, so you might want to try what works best for you.这些库中的每一个都有自己的警告,因此您可能想尝试最适合您的。

This method works for me.这个方法对我有用。

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

  2. create setup.py.创建 setup.py。 I'm using PyCharm.我正在使用 PyCharm。 This will ( https://www.jetbrains.com/help/pycharm/creating-and-running-setup-py.html ) write these commands in your project directory.这将 ( https://www.jetbrains.com/help/pycharm/creating-and-running-setup-py.html ) 在您的项目目录中写入这些命令。

  3. sudo apt-get install python3-stdeb fakeroot python-all sudo apt-get install python3-stdeb fakeroot python-all
  4. python3 setup.py sdist python3 setup.py sdist
  5. sudo python3 setup.py --command-packages=stdeb.command bdist_deb须藤 python3 setup.py --command-packages=stdeb.command bdist_deb
  6. your deb file is in the deb_dist directory that is in your project您的 deb 文件位于项目中的 deb_dist 目录中

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

相关问题 分发Python程序 - Distributing Python programs 将python软件包分发到离线计算机 - Distributing python packages to offline machines 将Python应用程序作为debian包分发,但作为服务 - Distributing Python application as a debian package, but as service 通过stdeb从Django项目分发Debian软件包 - Distributing Debian packages from Django project via stdeb Debian 包是否有标准/推荐的目录结构? - Is there a standard/recommended directory structure for Debian packages? 对于不同的Linux发行版(Debian,Redhat,Slackware等),python标准库和dist-packages的路径是否不同? - Are the paths to the python standard library and to the dist-packages different for different linux distributions(Debian, Redhat, Slackware, …)? 一种使用python和标准包通过ssh执行命令的方法 - a way to execute commands over ssh with python with standard packages 如何创建一个只有标准库,没有额外包的 Python 3 环境 - How to create a Python 3 environment that has only standard lib, no extra packages 使用 setup.py for Python 分发多个包 - Distributing multiple packages using setup.py for Python 分发依赖于内部常见便捷库的Python包 - Distributing Python packages which depend on in-house common convenience libraries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM