Create virtualenvs in project directories

It's quite handy to create the virtual environment aka venv for a python project in the project folder itself. This means:

  1. No huge .virtualenvs folder in your home directory with a lot of envs which you will never use again (The one on this computer is 1.2 GB big although I do not work with many Python projects at all(!)). If you are done with a project and delete all local files, the corresponding environment will be gone with it.
  2. Pointing your editor/IDE to the current virtual env as well as deleting it is easy, because it is right there in the project root folder.

As there are many tools in this realm, obviously every one of them handles things a little bit differently and it is the default for none of the popular ones:

[Read More]

Why does poetry not use the specified Python version?

TL;DR: There is only one way to install poetry proper and that is with the installer script provided by the project itself.

I was sweating for the better part of an afternoon with a colleague about this. I had installed poetry, the new star in the python tooling world and it kept using the global version of Python instead the one for the project at hand, though poetry's own pyproject.toml specifies it. It was quite a frustrating experience.

[Read More]

Missing system modules in Python

I got to work on a Python code-base in the last days and have been struggling to get to a stable development environment. I learned some lessons along the way. Here is one of them, as it seems to be rather common and causes headaches for many people (a simple search has a whopping half a million hits on Google).

The error

ModuleNotFoundError: No module named '_lzma'

I found this error at the bottom of a very long stack trace after running a unit test. That was suprising as the tests had worked fine before. I stashed all current changes, but the error persisted. I recognized that the lzma module is part of the standard library. I could not find the module _lzma though. It turned out that the problem could be reproduced with a simple import statement:

[Read More]