How Use Python on NixOS, the Pythonic Way

Struggling to use Python properly on NixOS is one of the most common pitfalls for newcomers. As a pythonista myself, I have been through all the pain and can now share my learnings.

The blog post describes the motivation for my recent contribution to Home Manager that is meant to help pythonistas love NixOS without having to sacrifice their love for Python. HM’s programs.uv gets a python and a tool option to manage Python the pythonic way, declaratively.

Pythonistas can now combine the famous Python freedom with the advantages of using a distribution with built-in configuration management. The article ends with a motivational outlook for pythonistas to become NixOS fanboys over time, without having to go through countless valleys of tears.

4 Likes

I keep many python projects, and use direnv.

Very interesting implementations, I had mainly patched my devshells to bridge the gap by providing python and uv then using uv’s lock for deps. This is a good addition for new ideas.

It works. But step back and look at what just happened: to import numpy

After fighting with poetry for a while I eventually just went fully with Nix for Python environments.

One thing that stil remains is that certain tools use the default Python from Nixpkgs. When you then specify a specific Python version for your environment it sometimes can get weird behaviours because the PYTHONPATHS are leaking through.

1 Like