Nixpkgs-python: use any Python using Nix

Hi all!

Have you ever wanted to use a specific version of Python using Nix?

Supports all Python versions from 2.7.6 to the latest 3.11.3, updated hourly.


Is it possible to specify which pip packages should be included in the installation?

1 Like

Took me a moment to digest that flake.nix, but it just builds the nixpkgs python package with a bunch of overrides for each version of python applied.

In other words, @kzvi, yes - unless I’m very mistaken.

@domenkozar in fact modularized the upstream python definitions to fully accept building various versions, including the passthrus, which include the withPackages function: nixpkgs/passthrufun.nix at b19f607a1b1d36a02741cf3aefe674bd3848fcf6 · domenkozar/nixpkgs · GitHub

This is very cool :slight_smile: I don’t think it caches pip packages, though, so you’ll need to “build” those downstream?



You can see how I install packages using pip in nixpkgs-python devenv.nix.

1 Like

you gave some example using flake on your readme, how could i create a simple nix file instead using it? Could you give me an example, please?

Perhaps something like this, depending on how you want to use it:

$ nix-shell
bash-5.2$ python2.7
Python 2.7.18 (default, Jul 12 2023, 15:16:47)
[GCC Clang 11.1.0] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print "statements omg"
statements omg

bash-5.2$ cat shell.nix
  pkgs = (import (fetchTarball "") { });
  nixpkgs-python = import  (fetchTarball "");
  pkgs.mkShell {
    buildInputs = [
1 Like

FYI I added the link to the nixos wiki (in the first section aswell as in the “See also”). Hope that’s fine/correct.

1 Like