Bioinformatic analysis · Bioinformatics software/pipeline development · Long-read RNA-seq
06 July 2022
While writing my first python software library, Swan, I struggled to figure out how to upload my library to the Python Package Index (PyPi, or pip
), to make it installable from the command line. Hopefully these instructions will help someone else that’s interested in learning how.
my_library/my_library
. Your .py
files should be in my_library/my_library
.import my_library
)..py
files, (ie my_library/
), create the following files:
setup.py
setup.cfg
LICENSE.txt
README.txt
setup.py
.
install_requires
section of setup.py
) using pipreqs
. This will automatically write all imported packages in your library to a requirements.txt
file. These requirements are strict and you may want to relax these requirements if you believe your library will work with other versions of these requirements.
pip install pipreqs
pipreqs ~/mortazavi_lab/bin/swan_vis/swan_vis/
setup.cfg
. You can likely just use this file.LICENSE.txt
. If you want to use the MIT license, use this file.setuptools
pip install setuptools
my_library/
, run:
python setup.py sdist
twine
, which will upload your library to PyPi
pip install twine
my_library/
directory:
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
pip install -i https://test.pypi.org/pypi/ --extra-index-url https://pypi.org/simple my_library
import my_library
You can and should also try some simple tests using the functionality of your library to ensure that it works.
my_library/
directory:
twine upload dist/*
pip install my_library
download_url
in setup.py
with the link to the tar.gz
file containing your release on GitHub.version
in setup.py
with the new version number that you assigned to your release on GitHub.dist/
my_library.egg_info/
If you don’t remove these, twine
will try to reupload an old distribution, and PyPi cannot accommodate two libraries with the same name / version ID.
my_library/
python setup.py sdist
References / additional resources:
setup.py
scriptrequirements.txt