Setup Python Development Environment

Tools

My Python development environment is mainly created and maintained with the following tools for different use scenarios:

In contrast to poetry, pipenv project is less active recently. However, I use both still as they are focusing on slightly different problems.

I will elaborate more details regarding how and when I use them in the following of this post.

Setup

I have put all setup steps in this repository. Please refer to scripts/dev-env-python.sh in the repository.

If you are using Ubuntu 20.04, by invoking scripts/dev-env-python.sh will setup everything for you.

When to Use Pipenv

If I would like to create a python virtual environment to try something quickly, I will consider to use pipenv, especially when I want to specify python version to try as pipenv could invoke python-build of pyenv to build different versions of python.

For example, a lot of individual python scripts are used in my daily jobs in different projects. I will consider to use pipenv for each such project.

When to Use Poetry

In contract with pipenv, poetry is more project-orientated. poetry is NOT a python version management tool. If poetry can't figure out which python version to use, it will use a "default" version, or we should tell poetry at where the python interpreter is.

If I would like to initiate a python project with well-defined structure, I will consider to use poetry instead of pipenv. If the project I am involving in is using poetry, then there is no doubt to use poetry.

Acknowledgement

This best practice is inspired mostly by TP's presentatioin in Python Conference Taiwan 2018 (Speak in Mandarin with English slides). I am enlighted by this talk very much. It's a must-watch video when learning how to get your python development environment ready, even you are a MacOS or Windows Python developer. This talk covers Linux distrobutions, MaCOS, and Windows.