I've recently started working on new open-source projects and decided to publish a post a basic tutorial on how to package your Python code.
This tutorial doesn't describe the only way of doing things, merely one specific approach that I use.
Python module/package names should generally follow the following constraints:
The structure below
myproject/ myproject/ __init__.py a_module.py setup.py setup.cfg docs/ tests/ Authors README.rst LICENSE ChangeLog MANIFEST.in requirements.txt
"Requirements files" are files containing a list of items to be installed using pip install like so:
In our case we use the requirements.txt file in the setup.py with setuptools to install dependencies.
The myproject/MANIFEST.in includes additional files to the package.
include Authors include README.rst include LICENSE include requirements.txt
You can use setup.py to register your project on PyPI which is explained later or use it to remove, install your package.
will install the package
The develop will not install the package but it will create a .egg-link in the deployment directory back to the project source code directory.
So it's like installing but instead of copying to the site-packages it adds a symbolic link (the .egg-link acts as a multiplatform symbolic link).
That way you can edit the source code and see the changes directly without having to reinstall every time that you make a little change. This is useful when you are the developer of that project hence the name develop.
This tells PyPI where your README file is.
[metadata] description-file = README.rst
This file will contain whichver license you want your code to have. I tend to use the BSD 3-Clause license.
From the official website:
PyPI — the Python Package Index
The Python Package Index is a repository of software for the Python programming language.
Upload your code on PyPI. It's a big list of python packages that you absolutely must submit your package to for it to be easily one-line installable.
On PyPI Live and also on PyPI Test, you must create an account in order to be able to upload your code. I recommend using the same email/password for both accounts, just to make your life easier when it comes time to push.
[distutils] index-servers = pypi pypitest [pypi] repository=https://pypi.python.org/pypi username=your_username [pypitest] repository=https://testpypi.python.org/pypi username=your_username
This will attempt to register your package against PyPI's test server, just to make sure you've set up everything correctly.
Now upload your package
Simply run above commands again and replace pypitest with pypi
If you receive an error TypeError: cannot concatenate 'str' and 'NoneType' objects this is a known bug. Its because the upload is not prompting for the password.
To work around this register and upload at the same time like so: