Distributing Python modules for development

1 minute read

Sometimes you write or (more likely to be my case) modify already existing python modules to suit your needs. If these modifications are crucial in a particular pipeline that you want others to reproduce (like in a research paper) or you are using that module over and over again, it might be a good idea to prepare the package to be installed using pip from GitHub.

I learned to do it. I am collecting here some notes for future reference.

I followed the instructions provided in the Python Packaging User Guide from the beginning to section Working in “Development Mode” included. I found very enlightening Scott Torborg’s tutorial How To Package Your Python Code.

I am using PyCQP_interface as an example of a module prepared to be distributed over GitHub.

Basically:

  1. Produce a README file describing the package.
  2. Produce a LICENSE file.
  3. Copy the file setup.py
  4. Modify setup.py:
    1. line 17, since my README file is README.md;
    2. line 21, PyCQP_interface, the name of the module;
    3. line 26, 1.0.0, choose the appropriate version;
    4. line 28, add a short description;
    5. line 32, add the URL to the GitHub repository;
    6. line 35, add name;
    7. line 36, add e-mail;
    8. line 39, license;
    9. line 63, keywords;
    10. line 77, required packages; and
    11. add line 88, python_requires='>=3' to indicate only compatible with Python 3.

Once you have setup.py ready, push to the repository and then install it in a local environment using:

pip install -e git+https://github.com/chozelinek/PyCQP_interface.git#egg=pycqp-interface

And that’s it! If you have written a general purpose Python package and you would like to officially share it with the Python community, you should follow the instructions from the Python Packaging Authority to make it available through the Python Package Index.

Tags:

Categories:

Updated: