Search code examples
pythonpython-2.7python-3.xpackagedeb

How to create a package with a python file?


Hello I have this python file main.py like this :

print "a"

This file is really simple and I would like to create a deb file for this python file. Then I would like when I type for instance main in the terminal when the package is installed main I get :

a

Thank you very much !


Solution

  • If you want to run main.py from the command line:

    In your main.py you need to add a python shebang:

    #!/usr/bin/python
    print "a"
    

    In a terminal navigate to where your file is saved and run the following commands:

    chmod +x main.py
    sudo cp main.py ~/bin/
    

    Now you can type main.py on the terminal and your command should run. If you rename your file to main, then you'll only have to type main to get it to run.

    If you actually want to create a deb package:

    If you actually want to create a deb file, then follow this link.