<tfoot id='IrA9r'></tfoot>

<legend id='IrA9r'><style id='IrA9r'><dir id='IrA9r'><q id='IrA9r'></q></dir></style></legend>

  • <i id='IrA9r'><tr id='IrA9r'><dt id='IrA9r'><q id='IrA9r'><span id='IrA9r'><b id='IrA9r'><form id='IrA9r'><ins id='IrA9r'></ins><ul id='IrA9r'></ul><sub id='IrA9r'></sub></form><legend id='IrA9r'></legend><bdo id='IrA9r'><pre id='IrA9r'><center id='IrA9r'></center></pre></bdo></b><th id='IrA9r'></th></span></q></dt></tr></i><div id='IrA9r'><tfoot id='IrA9r'></tfoot><dl id='IrA9r'><fieldset id='IrA9r'></fieldset></dl></div>
      • <bdo id='IrA9r'></bdo><ul id='IrA9r'></ul>

        <small id='IrA9r'></small><noframes id='IrA9r'>

        如何使用 CPack 构建 debian 包来执行 setup.py?

        时间:2023-09-13
        • <tfoot id='fqKIR'></tfoot>

          <legend id='fqKIR'><style id='fqKIR'><dir id='fqKIR'><q id='fqKIR'></q></dir></style></legend>
            <tbody id='fqKIR'></tbody>
              <bdo id='fqKIR'></bdo><ul id='fqKIR'></ul>

              • <small id='fqKIR'></small><noframes id='fqKIR'>

                  <i id='fqKIR'><tr id='fqKIR'><dt id='fqKIR'><q id='fqKIR'><span id='fqKIR'><b id='fqKIR'><form id='fqKIR'><ins id='fqKIR'></ins><ul id='fqKIR'></ul><sub id='fqKIR'></sub></form><legend id='fqKIR'></legend><bdo id='fqKIR'><pre id='fqKIR'><center id='fqKIR'></center></pre></bdo></b><th id='fqKIR'></th></span></q></dt></tr></i><div id='fqKIR'><tfoot id='fqKIR'></tfoot><dl id='fqKIR'><fieldset id='fqKIR'></fieldset></dl></div>
                  本文介绍了如何使用 CPack 构建 debian 包来执行 setup.py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  到目前为止,我的项目只有 .cpp 文件被编译成不同的二进制文件,我设法配置 CPack 来构建一个合适的 debian 包 没有任何问题.

                  Until now, my project had only .cpp files that were compiled into different binaries and I managed to configure CPack to build a proper debian package without any problems.

                  最近我编写了几个 python 应用程序并将它们添加到项目中,以及一些我也想合并到包中的自定义模块.

                  Recently I wrote a couple of python applications and added them to the project, as well as some custom modules that I would also like to incorporate to the package.

                  编写 setup.py 脚本后,我想知道如何以 setup.pyCPack 配置中code> get 会在用户使用 dpkg -i package.deb 在系统上安装包时自动执行.

                  After writing a setup.py script, I'm wondering how to add these files to the CPack configuration in a way that setup.py get's executed automatically when the user installs the package on the system with dpkg -i package.deb.

                  我正在努力寻找有关如何配置 CPack 以安装自定义 python 应用程序/模块的相关信息.有人试过吗?

                  I'm struggling to find relevant information on how to configure CPack to install custom python applications/modules. Has anyone tried this?

                  推荐答案

                  我想出了一个办法,但不是很简单.我会尽力解释程序,所以请耐心等待.

                  I figured out a way to do it but it's not very simple. I'll do my best to explain the procedure so please be patient.

                  在定义项目的 CMakeLists.txt 中,您需要声明 CPACK 将用于生成 .deb 包.有一些变量需要填写与包本身相关的信息,但是一个名为 CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA 的变量非常重要,因为它用于指定 postinst 的位置prerm,它们是 debian 打包系统 的标准脚本,在安装/删除软件包时由 dpkg 自动执行.

                  In the CMakeLists.txt that defines the project, you need to state that CPACK is going to be used to generate a .deb package. There's some variables that need to be filled with info related to the package itself, but one named CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA is very important because it's used to specify the location of postinst and prerm, which are standard scripts of the debian packaging system that are automatically executed by dpkg when the package is installed/removed.

                  在你的 ma​​in CMakeLists.txt 的某个时刻,你应该有这样的东西:

                  At some point of your main CMakeLists.txt you should have something like this:

                  add_subdirectory(name_of_python_app)
                  
                  set(CPACK_COMPONENTS_ALL_IN_ONE_PACKAGE 1)
                  
                  set(CPACK_PACKAGE_NAME "fake-package")
                  set(CPACK_PACKAGE_VENDOR "ACME")
                  set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "fake-package - brought to you by ACME")
                  set(CPACK_PACKAGE_VERSION "1.0.2")
                  set(CPACK_PACKAGE_VERSION_MAJOR "1")
                  set(CPACK_PACKAGE_VERSION_MINOR "0")
                  set(CPACK_PACKAGE_VERSION_PATCH "2")
                  SET(CPACK_SYSTEM_NAME "i386")
                  
                  set(CPACK_GENERATOR "DEB")
                  set(CPACK_DEBIAN_PACKAGE_MAINTAINER "ACME Technology")
                  set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libgcc1 (>= 1:3.4.2-12), python2.6, libboost-program-options1.40.0 (>= 1.40.0)")
                  set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/name_of_python_app/postinst;${CMAKE_SOURCE_DIR}/name_of_python_app/prerm;")
                  set(CPACK_SET_DESTDIR "ON")
                  
                  include(CPack)
                  

                  其中一些变量是可选的,但出于教育目的,我会用信息填充它们.

                  Some of these variables are optional, but I'm filling them with info for educational purposes.

                  现在,让我们看一下脚本:

                  Now, let's take a look at the scripts:

                  postinst:

                  #!/bin/sh
                  # postinst script for fake_python_app
                  
                  set -e
                  
                  cd /usr/share/pyshared/fake_package
                  sudo python setup.py install
                  

                  预售:

                  #!/bin/sh
                  # prerm script
                  #
                  # Removes all files installed by: ./setup.py install
                  sudo rm -rf /usr/share/pyshared/fake_package
                  sudo rm /usr/local/bin/fake_python_app
                  

                  如果您注意到,脚本 postinst 进入 /usr/share/pyshared/fake_package 并执行放置在那里的 setup.py在系统上安装应用程序.这个文件来自哪里以及它是如何在那里结束的?该文件由您创建,当您的软件包安装在系统上时,该文件将被复制到该位置.这个动作在name_of_python_app/CMakeLists.txt中配置:

                  If you noticed, script postinst enters at /usr/share/pyshared/fake_package and executes the setup.py that is laying there to install the app on the system. Where does this file come from and how it ends up there? This file is created by you and will be copied to that location when your package is installed on the system. This action is configured in name_of_python_app/CMakeLists.txt:

                  install(FILES setup.py
                          DESTINATION "/usr/share/pyshared/fake_package"
                  )
                  
                  install(FILES __init__.py
                          DESTINATION "/usr/share/pyshared/fake_package/fake_package"
                  )
                  
                  install(FILES fake_python_app
                          DESTINATION "/usr/share/pyshared/fake_package/fake_package"
                  )
                  
                  install(FILES fake_module_1.py
                          DESTINATION "/usr/share/pyshared/fake_package/fake_package"
                  )
                  
                  install(FILES fake_module_2.py
                          DESTINATION "/usr/share/pyshared/fake_package/fake_package"
                  )
                  

                  您可能知道,除了我要安装的 python 应用程序之外,我还编写了 2 个自定义 python 模块,它们也需要安装.下面我描述了最重要的文件的内容:

                  As you can probably tell, besides the python application I want to install there's also 2 custom python modules that I wrote that also need to be installed. Below I describe the contents of the most important files:

                  setup.py:

                  #!/usr/bin/env python
                  from distutils.core import setup
                  
                  setup(name='fake_package',
                        version='1.0.5',
                        description='Python modules used by fake-package',
                        py_modules=['fake_package.fake_module_1', 'fake_package.fake_module_2'],
                        scripts=['fake_package/fake_python_app']
                       )
                  

                  _init_.py:是一个空文件.

                  _init_.py: is an empty file.

                  fake_python_app:将安装在/usr/local/bin 中的 Python 应用程序

                  fake_python_app : your python application that will be installed in /usr/local/bin

                  差不多就是这样!

                  这篇关于如何使用 CPack 构建 debian 包来执行 setup.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  1. <legend id='Od32N'><style id='Od32N'><dir id='Od32N'><q id='Od32N'></q></dir></style></legend>

                      <tbody id='Od32N'></tbody>

                    <small id='Od32N'></small><noframes id='Od32N'>

                      <i id='Od32N'><tr id='Od32N'><dt id='Od32N'><q id='Od32N'><span id='Od32N'><b id='Od32N'><form id='Od32N'><ins id='Od32N'></ins><ul id='Od32N'></ul><sub id='Od32N'></sub></form><legend id='Od32N'></legend><bdo id='Od32N'><pre id='Od32N'><center id='Od32N'></center></pre></bdo></b><th id='Od32N'></th></span></q></dt></tr></i><div id='Od32N'><tfoot id='Od32N'></tfoot><dl id='Od32N'><fieldset id='Od32N'></fieldset></dl></div>

                        <tfoot id='Od32N'></tfoot>
                        • <bdo id='Od32N'></bdo><ul id='Od32N'></ul>