We assume that we are creating a package shortpath.
The package should contain these files.
README.rst
MANIFEST.in
setup.py
setup.cfg (If you have any configuration to your package)
Now we have to build our setup.py based on our package details, for creating setup.py follow this.
If you are done with the above steps, your package structure will be something like
/shortpath
shortpath/
__init__.py
shortpath.py
MANIFEST.in
README.rst
__init__.py
setup.py
The shortpath.py will contain your methods, classes. Now, you can test your package locally using
$ pip install -e . >>> import shortpath >>> print some_method()
Now for uploading your package to PyPI,
$ pip install twine
Follow the link for registering on PyPI and configuring .pypirc
To generate your package distribution
$ python setup.py sdist
To generate you package info
$ python setup.py egg_info
Now upload your package with command
$ twine upload dist/*
Install the uploaded package
$ pip install shortpath
Note: If any error in installing the package it must be conflicting with the local package so remove the local package and symlink
- The packages you will find in
/usr/local/lib/python/dist-packages/
- The symlink will be in
/usr/local/lib/python/dist-packages/easy-install.pth
One thought on “Create a Python package?”