Friday, May 3, 2024
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 6794  / 1 Year ago, fri, december 2, 2022, 2:36:51

I have one Python file, main.py. I would like to be able to make a .deb package from it, and then be able to run main.py by typing the package name from the terminal. It is written in Python 3, so the package name should run:



python3 main.py


The only dependency I know of is python3.



I have tried creating a deb with a dependency of python3, and then running python3 packagename, but I get:



/usr/bin/python3: can't find '__main__' module in 'packagename'


Trying to use Debreate for package creation fails to open with :



Traceback (most recent call last):
File "/usr/bin/debreate", line 12, in <module>
import wx, sys, os, debreate, db, language, shutil
File "/usr/share/debreate/debreate.py", line 23, in <module>
import os, sys, wx.lib.dialogs, db, webbrowser, language, shutil, subprocess
File "/usr/share/debreate/db.py", line 5, in <module>
import wx, wx.combo, wx.lib.mixins.listctrl as LC, os, sys, language
ImportError: No module named combo

More From » command-line

 Answers
6

Creating a .deb for a python3 script is very simple, and only requires a few changes in debian/rules and debian/control if you're familiar with python2 packaging.



In a nutshell:




  1. Create the package source dir



    mkdir myscript-0.1

  2. Copy your python3 script (or the sample script below) to the source dir



    cp ~/myscript myscript-0.1
    cd myscript-0.1


    Sample script:



    #!/usr/bin/python3

    if __name__ == '__main__':
    print("Hello world")

  3. Create the packaging skeleton (debian/*)



    dh_make -s --indep --createorig

  4. Remove the example files



    rm debian/*.ex debian/*.EX debian/README.*

  5. Edit debian/control



    Replace its content with the following text:



    Source: myscript
    Section: utils
    Priority: optional
    Maintainer: Name,
    Build-Depends: debhelper (>= 9), python3
    Standards-Version: 3.9.5
    X-Python3-Version: >= 3.2

    Package: myscript
    Architecture: all
    Depends: ${misc:Depends}, ${python3:Depends}
    Description: insert up to 60 chars description
    insert long description, indented with spaces

  6. debian/install must contain the script to install as well as the target directory



    echo myscript usr/bin > debian/install

  7. Edit debian/rules



    Replace its content with the following text:



    #!/usr/bin/make -f

    %:
    dh $@ --with=python3


    Note: it's a TAB before dh $@, not four spaces!


  8. Build the package



    debuild -us -uc



You will get a few Lintian warnings/errors but your package is ready to be used:



../myscript_0.1-1_all.deb

[#27687] Saturday, December 3, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
afisird

Total Points: 193
Total Questions: 112
Total Answers: 111

Location: Angola
Member since Mon, Jul 12, 2021
3 Years ago
afisird questions
Wed, Jul 27, 22, 03:53, 2 Years ago
Sun, Mar 12, 23, 18:05, 1 Year ago
Sun, Dec 11, 22, 01:19, 1 Year ago
;