A simple CLI tool to use Python venv "normally" on NixOS
Shell
167
23 commits
updated Jul 12, 2025
Work with Python "normally" on NixOS in one command!
Tired of all these "*.so not found" errors? Change the RPATH of all the binaries in your venv!
nix-command and flakes experimental features must be enabledUse temporarily in a shell
nix shell github:GuillaumeDesforges/fix-python
Or add it to your profile
nix profile install github:GuillaumeDesforges/fix-python
In your Python project, create a virtual environment .venv and use your preferred tool (pip, poetry, ...) to install your dependencies.
[!IMPORTANT]
fix-pythonwill patch binary files in the virtual environment without following symlinks.For example, if you use the
venvmodule from Python's standard library, please make sure you pass--copieswhen creating the environment.python -m venv .venv --copies
By default, fix-python patches the packages given in the following expression:
let pkgs = import (builtins.getFlake "nixpkgs") { };
in [
pkgs.gcc.cc
pkgs.glibc
pkgs.zlib
]
Note: these three packages are fundamental for most Python packages and should never be removed.
If you need to patch packages in addition to these, create a .nix/libs.nix file with a structure similar to the above that returns the array of packages that you want binaries to be linked with.
Note: you may add this
.nixfolder to your project.gitignore.
Finally, call fix-python.
fix-python --venv .venv [--libs .nix/libs.nix]
The list of options is:
$ ./fix-python --help
Usage: fix-python --venv .venv [--libs libs.nix] [--no-default-libs]
--help: show this help message
--venv: path to Python virtual environment
--libs: path to a Nix file which returns a list of derivations
--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default
--gpu: enable GPU support
--with-torch: fix pytorch dependencies issues
--deep: looks for anything executable to patch, very slow but needed sometimes (e.g. PyQt)
--verbose: increase verbosity
Shell
92.2%
Nix
7.8%
A simple CLI tool to use Python venv "normally" on NixOS
Shell
167
23 commits
updated Jul 12, 2025
Work with Python "normally" on NixOS in one command!
Tired of all these "*.so not found" errors? Change the RPATH of all the binaries in your venv!
nix-command and flakes experimental features must be enabledUse temporarily in a shell
nix shell github:GuillaumeDesforges/fix-python
Or add it to your profile
nix profile install github:GuillaumeDesforges/fix-python
In your Python project, create a virtual environment .venv and use your preferred tool (pip, poetry, ...) to install your dependencies.
[!IMPORTANT]
fix-pythonwill patch binary files in the virtual environment without following symlinks.For example, if you use the
venvmodule from Python's standard library, please make sure you pass--copieswhen creating the environment.python -m venv .venv --copies
By default, fix-python patches the packages given in the following expression:
let pkgs = import (builtins.getFlake "nixpkgs") { };
in [
pkgs.gcc.cc
pkgs.glibc
pkgs.zlib
]
Note: these three packages are fundamental for most Python packages and should never be removed.
If you need to patch packages in addition to these, create a .nix/libs.nix file with a structure similar to the above that returns the array of packages that you want binaries to be linked with.
Note: you may add this
.nixfolder to your project.gitignore.
Finally, call fix-python.
fix-python --venv .venv [--libs .nix/libs.nix]
The list of options is:
$ ./fix-python --help
Usage: fix-python --venv .venv [--libs libs.nix] [--no-default-libs]
--help: show this help message
--venv: path to Python virtual environment
--libs: path to a Nix file which returns a list of derivations
--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default
--gpu: enable GPU support
--with-torch: fix pytorch dependencies issues
--deep: looks for anything executable to patch, very slow but needed sometimes (e.g. PyQt)
--verbose: increase verbosity
Shell
92.2%
Nix
7.8%