6

How do I create a deb package for distribution from a directory of python project on Ubuntu 16.04?

I did search for it and the closest I found is this

What I have right now is a directory consists of a REST server written in python. I want to convert this directory to a deb package so the person who get the package can easily installed on their computer to run the REST server.

The detail of directory structure is like below

server
  |--api-----------------
  |                |--__init__.py
  |--main.py       |--v1---------------
  |                                |---__init__.py
  |--__init__.py                   |---resources-------
                                                |
                                                |---a.py
                                                |---b.py
                                                |---tasks.py

Normally, I run this server as python main.py after running a celery worker by typing celery -A server.api.v1.resources.tasks worker --loglevel=INFO

What I want to ask now is there a way to convert this project into deb packages for distribution? Since I also use celery worker for supporting the server, is it possible to convert this directory together with the command for the worker? What I mean here is that when someone run the deb package on his/her ubuntu computer, the server can run together with the worker.

Yaron
  • 13,173
Fang
  • 161

1 Answers1

1

Try fpm.

Installing from the docs cited:

$ sudo apt-get install ruby ruby-dev rubygems build-essential 
% sudo gem install --no-ri --no-rdoc fpm 

After fpm is installed:

$ cd server
$ fpm -s python -t deb .

Some customization for your particular situation. You could add "celery" to install_requires of setup.py. Also fpm options --python-install-bin and --python-install-lib might be used to specify where binary and library files should go. Further documentation of the python source is located as well.

You might also need to create some sort of custom script to kick this off.

rocky
  • 807
  • you might add information on how OP could use fpm to add deb package dependencies, so they would automatically be installed alongside the python project: -d, --depends DEPENDENCY A dependency. This flag can be specified multiple times. Value is usually in the form of: -d 'name' or -d 'name > version' – Phillip -Zyan K Lee- Stockmann Jan 17 '18 at 15:00
  • also I'm not experienced with package type python. if this would not work, OP could use -s dir – Phillip -Zyan K Lee- Stockmann Jan 17 '18 at 15:02