First things first, you need to properly structure your project. A quick guide on how to structure a python library can be found at the following links: in french and in english.

We will take one example: the sample python package…which only purpose is to explain how to properly structure and distribute a project. The sources can be found on GitHub.

Here is how the library is structured:

qdouasbin@jolly:~/Desktop/sampleproject>find . | sed -e "s/[^-][^\/]*\//  |/g" -e "s/|\([^ ]\)/|-\1/"
  |  |
  |  |
  |  |
  |  |-package_data.dat
  |  |-data_file

In short:

  • the repository must contain a file to easily install your library using the nice and simple install mechanisms described above. You can also specify your configuration in the setup.cfg but the still need to be present. More info here
  • your sources must be contained in a folder named as the library name (here the sample directory) you want to create,
  • you should have a LICENSE.txt or explicitly explaining under which software license your packages falls into,
  • the (or README.rst) should explain what your library does and how you install it. (The is
  • you should have a tests folder containing unit tests,
  • the documentation related to you project should be contained in the docs folder
  • a requirement.txt file containing all the dependencies (i.e. the python packages needed by your library)

To create a pip-installable package you need to create a To test that your works you need to run the pip install . in the folder containing the If it doesn’t work you need to:

  1. pip uninstall my_project
  2. modify the
  3. re-run the pip install . command

There are a lot of ways to populate a file as there are many options. The best option here is to start from an existing one and modify it to your needs. You can take the one of the sample project for example or the template_module example if you have access to Nitrox (you might need to ask the rights to access this repository to Corentin Lapeyre).

More on this topic can be found in the setuptools’ documentation setuptools’ documentation.

Like this post? Share on: TwitterFacebookEmail

Keep Reading





Stay in Touch