[英]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.到目前为止,这是我认为我理解的内容。
CDBS
or debhelper
.CDBS
或debhelper
。 Debhelper is the recommended way for beginners. 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
目录中填充许多文件,这些文件阐明了文件需要复制到哪里,它们受制于什么版权和许可方案,它们具有什么依赖关系等......dh_make
command if the Python source also comes with a distutils' setup.py
script.setup.py
脚本,则步骤 #4 可以在很大程度上自动化dh_make
命令。 Now my questions:现在我的问题:
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). 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):
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/
调用您的脚本
Change all the folder permission to root:将所有文件夹权限更改为root:
chown root:root -R /path/to/ProgramName-Version
Change the script's permissions:更改脚本的权限:
chmod 0755 /path/to/the/script
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.这个方法对我有用。
install stdeb.安装标准数据库。 (pip install stdeb)
(pip 安装标准数据库)
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 ) 在您的项目目录中写入这些命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.