DEV Community

Cover image for Distribute a Python App via File
Niklas Tiede
Niklas Tiede

Posted on • Originally published at

Distribute a Python App via File

Heya fellows,

The code of this post can be found on Github (see here).

We have seen that it's tedious and unclear how to distribute a project with a bash script. So I'll show you in this post the way to go: using a file!

We have to create a file, put it into the root directory and then we can use pip to install our project locally. This installs the project into the active virtual environment. But how does a file looks like? Here's a template containing the most important key-value pairs:

import setuptools


    package_dir={"": "src"},


Enter fullscreen mode Exit fullscreen mode

The package_dir and packages values are necessary when a source layout is used, so that knows where to look for the packages. We used here a source layout to show these key-values and how they affect the entry_points section. The entry_points section tells pip where the command line tool is invoked from.

Alt Text

The command (in this case tihttp) is mapped to the starting point of the command line tool (here the run_main() function). Now tihttp can be installed and the command should return a proper help interface.

$ pip install .

$ tihttp --help
Enter fullscreen mode Exit fullscreen mode

Another big advantage of this setup is that pip allows to install packages in editable mode:

$ pip install -e .
Enter fullscreen mode Exit fullscreen mode

Your project is then installed into your currently activated virtual environment and every change to the code immediately affects this installed dependency. This allows to continue developing while testing the package comfortably. Furthermore, the file allows to download and install your project directly from github.

$ pip install
Enter fullscreen mode Exit fullscreen mode

Direct installations from github can take time especially for projects which are bigger (large git history) and use non-Python languages. Therefore PyPI and Anaconda are usually the preferred places to go for installing packages.

I want to note that many developers in the python community store project metadata and settings used for linting/testing within a setup.cfg file instead of a file but this is a topic for another post.

Top comments (0)