This post covers the basic of how to build and distribution your own Python package and upload it to Python package index (PyPI) library in order to the other develops of the end-users can install and use it easily. It is not difficult and everyone can do it! Follow the below instruction step-by-step, when it is done, you and other people can type just pip install your_project to install your package!
python --versionpip install setuptools wheel twine --upgrade --user#!/usr/bin/env pythonimport setuptools__version__ = "x.x.x" # version of your packagewith open("README.md", "r", encoding="utf-8") as f: long_description = f.read()description = "This is my project" # description of packagesetuptools.setup( name="YOUR_PACKAGE_NAME", # your package name version=__version__, author="PACKAGE_NAME", # author name author_email="AUTHOR_EMAIL", # author e-mail description=description, long_description=long_description, long_description_content_type="text/markdown", url="LINK_TO_WEBSITE", # link to project website download_url="RELEASE_FILE", # link to release archive project_urls={ 'Documentation': 'PROJECT_DOCS', # link to package document 'Source': 'PROJECT_SOURCE_CODE', # link to project source code }, packages=setuptools.find_packages(), install_requires=[ 'numpy' # list of package dependencies, fx, numpy ], classifiers=[ "Programming Language :: Python", "Programming Language :: Python :: 3", "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: OS Independent", "Intended Audience :: Developers", "Natural Language :: English", ], python_requires='>=3',)Build *.tar.gz source code archive and *whl distribution files using command:
python setup.py sdist bdist_wheelBoth *tar.gz and *whl will be built and stored in a ./dist directory.
Test-PyPI
twine upload --repository-url https://test.pypi.org/legacy/ dist/*Enter your username: rangsimanEnter your password: (invisible)Uploading distributions to https://test.pypi.org/legacy/Uploading octadist-2.5.3-py3-none-any.whl100%|████████████████████████████████████| 51.3k/51.3k [00:03<00:00, 14.5kB/s]Uploading octadist-2.5.3.tar.gz100%|████████████████████████████████████| 33.4k/33.4k [00:01<00:00, 20.7kB/s]PyPI
twine upload dist/*Enter your username: rangsimanEnter your password: (invisible)Uploading distributions to https://upload.pypi.org/legacy/Uploading octadist-2.5.3-py3-none-any.whl100%|████████████████████████████████████| 51.3k/51.3k [00:03<00:00, 14.5kB/s]Uploading octadist-2.5.3.tar.gz100%|████████████████████████████████████| 33.4k/33.4k [00:01<00:00, 20.7kB/s]Test-PyPI
pip search octadist --index https://test.pypi.org/pypiPyPI
pip search octadist --index https://pypi.org/pypior
pip search octadistpip show octadistSample output:
Name: octadistVersion: 2.5.3.1Summary: OctaDist: A tool for calculating distortion parameters in coordination complexes.Home-page: https://octadist.github.ioAuthor: Rangsiman KetkaewAuthor-email: rangsiman1993@gmail.comLicense: UNKNOWNLocation: c:\xxx\xxx\xxx\anaconda3\lib\site-packagesRequires: matplotlib, rmsd, numpy, scipyRequired-by:Test-PyPI
pip install --index-url https://test.pypi.org/simple/ octadistPyPI
pip install octadistRangsiman Ketkaew