Distributing Python modules for development
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:
- Produce a README file describing the package.
- Produce a LICENSE file.
- Copy the file
setup.py
- Modify
setup.py
:- line 17, since my README file is
README.md
; - line 21,
PyCQP_interface
, the name of the module; - line 26,
1.0.0
, choose the appropriate version; - line 28, add a short description;
- line 32, add the URL to the GitHub repository;
- line 35, add name;
- line 36, add e-mail;
- line 39, license;
- line 63, keywords;
- line 77, required packages; and
- add line 88,
python_requires='>=3'
to indicate only compatible with Python 3.
- line 17, since my README file is
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.