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
  • possible duplicate of How do I create a deb package for a single python script?
    – Aditya
    Jan 3, 2014 at 16:10
  • 1
    Aditya: all answers used python2. I need it to use python3.
    – meecoder
    Jan 3, 2014 at 16:11
  • 1
    I also need to be able to run the package from the command line. I tried this already but after installation i get command not found
    – meecoder
    Jan 3, 2014 at 16:14
  • 1
    I have left a comment below the post of @andrewsomething to update it for Python 3. In the meantime please edit your question to include what you have already tried and what are the results/error that you get.
    – Aditya
    Jan 3, 2014 at 16:15
  • 1
    – jfs
    Mar 10, 2014 at 9:10

2 Answers 2


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:

    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:

  • Do you know how to include translations (PO/POT) into the DEB file? I think there's a command needed within debian/rules but I've never been able to figure it out. Aug 16, 2014 at 0:21
  • 1
    @Bernmeister, Please create a new question about translation support. I'd prefer to keep this one as simple as possible. Thanks Aug 26, 2014 at 7:41
  • 1
    dh_make: error: argument -i/--indep: not allowed with argument -s/--single Sep 23, 2020 at 1:41

For the error you encounter in debreate,

sudo apt-get install python-wxgtk2.8

source: source of above solution

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .