10

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
meecoder
  • 135
  • 1
  • 10

2 Answers2

16

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
0

For the error you encounter in debreate,

sudo apt-get install python-wxgtk2.8

source: source of above solution