setuptools is a tool to download, build, install, upgrade, and uninstall Python packages — easily!
If you just need to install other people’s packages, this is NOT for you. All you need is pypi and knowing the command
pip install some-package
setuptools is for the other way round. It is for developers who want to distribute their SDK/library/packages to those “pip install” developers. There are 2 steps.
Step 1) setup.py
Install setuptools. For Mac, it basically downloading and running the egg.
Afterwhich, create a setup.py in the root of your Python project. A basic template looks like this:
import os from setuptools import setup, find_packages setup( name = "just2us", version = "0.0.1", author = "Junda Ong", author_email = "[email protected]", description = "Python SDK for Just2us", license = "MIT", keywords = "awesome stuff", url = "http://www.just2us.com", install_requires = ["requests"], packages = find_packages(), classifiers = [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Topic :: Software Development :: Libraries :: Python Modules", ], )
As you can see, setup() basically describes various things about your package, such as:
- meta eg. author email
- required dependencies
With that, you can install your Python package. This is usually what you do when you manually install from source.
python setup.py install
Step 2) Upload to Python CheeseShop
But instead of setting up manually, you could make use of Python CheeseShop (pipy) to distribute and setup your package for the Python community. This is the part which connects to pip install.
Firstly, register an account. (Take note: I failed registration a few times, without receiving the validation email. I think that is because of password too short/weak.) The registration is command line based:
python setup.py register
The Python Cheese Shop provides an example of a pypi project to be uploaded.
bdist_egg upload --identity="Andrew Carter" --sign --quiet bdist_wininst --target-version=2.4 register upload --identity="Andrew Carter" --sign --quiet sdist upload --identity="Andrew Carter" --sign
As a bonus, you might want to understand the difference on prerelease and postrelease versions:
- 1.2rc1 (same as 1.2c1)
- 1.2rc < 1.2
- 1.2-r2943 (as in revision 2943)
- 1.2-r2943 > 1.2