in

Extensive collection of Python projects from PyPI, for Nix


Extensive collection
of Python projects
from the Python Packaging Index.
That can be installed with the Nix package manager.

Checkout the projects folder,
each entry represents a project and its available versions.

For example:

  • Project: awscli and version: 1.20.31, or
  • Project: requests and version 2.26.0

If you want to refer to the latest version available you can do it:

  • Project: awscli and version latest, or
  • Project: requests and version: latest

If you want to only use the binaries of a project
you can install them on your system like this:

$ nix-env -iA 'apps."<project>"."<version>"' -f https://github.com/kamadorueda/nixpkgs-python/tarball/main

For example:

$ nix-env -iA 'apps."awscli"."latest"' -f https://github.com/kamadorueda/nixpkgs-python/tarball/main

or

$ nix-env -iA 'apps."awscli"."1.20.31"' -f https://github.com/kamadorueda/nixpkgs-python/tarball/main

After the process have completed,
you will be able to use the project’s binaries:


$ aws --version

  aws-cli/1.20.31 Python/3.9.6 Linux/5.10.62 botocore/1.21.31

:warning: You won’t be able to import the project libraries with Python (import xxx). If you want to do this please keep reading.

First,
you need to import Nixpkgs Python
into your project.

For example:

# /path/to/my/env.nix

let
  nixpkgs = import <nixpkgs> { };

  nixpkgsPython = import (nixpkgs.fetchFromGitHub {
    owner = "kamadorueda";
    repo = "nixpkgs-python";
    # Pick a commit from this list:
    # https://github.com/kamadorueda/nixpkgs-python/commits/main
    rev = "0000000000000000000000000000000000000000";
    # Update this manually
    sha256 = "0000000000000000000000000000000000000000000000000000";
  });
in
# Keep reading for more information

This repository offers you
the following functions.
Please pick the Python version of your choice:

  • python36Env: Python 3.6
  • python37Env: Python 3.7
  • python38Env: Python 3.8
  • python39Env: Python 3.9

For example:

# /path/to/my/env.nix (continuation)

nixpkgsPython.python39Env {
  name = "example";
  projects = with nixpkgsPython.projects; [
    awscli."1.20.31"
    numpy."latest"
    requests."latest"
    torch."1.9.0"
  ];
}

The output of this function
contains a setup script
that you can source:

# Build your environment
$ nix-build /path/to/my/env.nix

# Source it's output
$ source ./result/setup

After doing this,
the specified dependencies will be available in your shell ! :rocket:

Also, you’ll be able to use the applications and libraries provided
by the projects in the environment:

$ python --version

  Python 3.9.6

$ aws --version

  aws-cli/1.20.31 Python/3.9.6 Linux/5.10.57 botocore/1.21.31

$ python -c 'import numpy; print(numpy.__version__)'

  1.21.2

$ python -c 'import requests; print(requests.__version__)'

  2.26.0

$ python -c 'import torch; print(torch.__version__)'

  1.9.0+cu102

Compatibility with Nixpkgs

You can use Nixpkgs Python and Nixpkgs together.

For example:

# /path/to/my/expression.nix

let
  # import projects as explained in previous sections
  nixpkgs = import { ... };
  nixpkgsPython = import { ... };

  # Create a Nixpkgs Python environment as explained in previous sections
  env = nixpkgsPython.python39Env {
    name = "example";
    projects = with nixpkgsPython.projects; [
      awscli."1.20.31"
      numpy."latest"
      requests."latest"
      torch."1.9.0"
    ];
  };
in
nixpkgs.stdenv.mkDerivation {
  buildInputs = [ env ];
  builder = builtins.toFile "builder.sh" ''
    source $stdenv/setup

    set -x

    python --version
    aws --version
    python -c 'import numpy; print(numpy.__version__)'
    python -c 'import requests; print(requests.__version__)'
    python -c 'import torch; print(torch.__version__)'

    touch $out
  '';
  name = "example";
}

Now just $ nix-build /path/to/my/expression.nix ! :rocket:

these derivations will be built:
  /nix/store/4l51x7983ggxc8z5fmb5wzhvvx8kvn01-example.drv

building '/nix/store/4l51x7983ggxc8z5fmb5wzhvvx8kvn01-example.drv'...

+ python --version
Python 3.9.6

+ aws --version
aws-cli/1.20.31 Python/3.9.6 Linux/5.10.57 botocore/1.21.31

+ python -c 'import numpy; print(numpy.__version__)'
1.21.2

+ python -c 'import requests; print(requests.__version__)'
2.26.0

+ python -c 'import torch; print(torch.__version__)'
1.9.0+cu102

+ touch /nix/store/9cckx5zpbiakx507g253fv08hykf8msv-example

You can configure nixpkgs-python’s binary cache
to speed up your builds.

Anything you can think of will be appreciated!


GitHub – kamadorueda/nixpkgs-python: Extensive collection of Python projects from PyPI, for Nix

Extensive collection of Python projects from PyPI, for Nix – GitHub – kamadorueda/nixpkgs-python: Extensive collection of Python projects from PyPI, for Nix


Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

GIPHY App Key not set. Please check settings

Pub-Sub pattern: a brief explanation

A high-performance and strong-extensibility Golang RPC framework that helps developers build microservices