Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Extensive collection of Python projects from PyPI, for Nix!

License

NotificationsYou must be signed in to change notification settings

on-nix/python

Repository files navigation

Extensive collectionofPython projectsfrom thePython Packaging Index.That can be used with theNix package manager.

Check out the examples atpython.on-nix.com!

  • Scope:
  • Quality:
    • ✔️ It is 100% Nix, with love ❤️
    • ✔️ Data integrity checksums are used everywhere
    • ✔️ We test projects before you use them
  • Platforms:
    • ✔️ Linux x86-64
    • 🚧 MacOS x86-64
  • Performance:
    • ✔️ Every project is built with a minimal closure and size
    • ✔️ A highly granular cache

Why?

To make usingNix onPython projectsas simple as possible!

Just:

  1. Copy and paste the examples,
  2. Select thePython projects of your choice,
  3. Enjoy! 🚀

Contents

List of available projects

Checkoutpython.on-nix.com

Concepts

Applications and Libraries

On Python, projects can be used in two ways:

  • As applications: Commands that you can run from the command line:

  • As libraries: Python modules that you can import in your project:

Some projects (like PyTest) can be used in both wayswhile others can only be used as an application or as a library,but not both

Using with Nix stable

Trying out single projects

You can launch an ephemeral environment wherethe applications and libraries provided by a project are available.

For example:

$ nix-shell \  -A'projects."awscli"."1.20.31".python39.dev' \  https://github.com/on-nix/python/tarball/main

In general the format is:'projects."<project>"."<version>".<pythonVersion>.dev'

Now enjoy!

[nix-shell] $ aws --version              aws-cli/1.20.31 Python/3.9.6 Linux/5.10.62 botocore/1.21.31[nix-shell] $ python -c'import awscli; print(awscli)'# ...[nix-shell] $exit

Installing applications in your system

You can permanently install the applications of a project in your system.

For example:

$ nix-env \  -iA'apps."awscli"."1.20.31"' \  -f https://github.com/on-nix/python/tarball/main$ nix-env \  -iA'apps."pytest"."latest"' \  -f https://github.com/on-nix/python/tarball/main

In general the format is:'apps."<project>"."<version>"'

Now enjoy!

$ aws --version  aws-cli/1.20.31 Python/3.9.6 Linux/5.10.62 botocore/1.21.31$ pytest --version  pytest 6.2.5

Creating Python environments with many applications and libraries

For more complex use cases where you are using many projects it'sa good idea to describe a Python environment with Nix.

For example:

# /path/to/my/env.nixlet# Import Python on NixpythonOnNix=import(builtins.fetchGit{# Use `main` branch or a commit from this list:# https://github.com/on-nix/python/commits/main# We recommend using a commit for maximum reproducibilityref="main";url="https://github.com/on-nix/python";}){# (optional) You can override `nixpkgs` here# nixpkgs = import <nixpkgs> { };};# Pick the Python version of your choice:# - `python37Env`: Python 3.7# - `python38Env`: Python 3.8# - `python39Env`: Python 3.9# - `python310Env`: Python 3.10env=pythonOnNix.python39Env{name="example";projects={awscli="1.20.31";numpy="latest";requests="latest";torch="1.9.0";};};# `env` has two attributes:# - `dev`: The activation script for the Python on Nix environment# - `out`: The raw contents fo the Python site-packagesin# Let's use the activation script:env.dev

You can now launch the environment!

$ nix-shell /path/to/my/env.nix

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

Also, you'll be able to use the applications and libraries providedby 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 usePython On Nix andNixpkgs together.

For example:

# /path/to/my/expression.nixlet# Import Nixpkgsnixpkgs=import<nixpkgs>{};# Import Python on NixpythonOnNix=import(builtins.fetchGit{# Use `main` branch or a commit from this list:# https://github.com/on-nix/python/commits/main# We recommend using a commit for maximum reproducibilityref="main";url="https://github.com/on-nix/python";}){# Make Python on Nix use the same version of `nixpkgs`# for maximum compatibilityinheritnixpkgs;};# Pick the Python version of your choice:# - `python37Env`: Python 3.7# - `python38Env`: Python 3.8# - `python39Env`: Python 3.9# - `python310Env`: Python 3.10env=pythonOnNix.python39Env{name="example";projects={awscli="1.20.31";numpy="latest";requests="latest";torch="1.9.0";};};# `env` has two attributes:# - `dev`: The activation script for the Python on Nix environment# - `out`: The raw contents of the Python virtual environmentinnixpkgs.stdenv.mkDerivation{# Let's use the activation script as build input:buildInputs=[env.dev];virtualEnvironment=env.out;builder=builtins.toFile"builder.sh"''    source $stdenv/setup    set -x    ls $virtualEnvironment    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    set +x  '';name="example";}

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

these derivations will be built:  /nix/store/4l51x7983ggxc8z5fmb5wzhvvx8kvn01-example.drvbuilding'/nix/store/4l51x7983ggxc8z5fmb5wzhvvx8kvn01-example.drv'...+ ls /nix/store/...-example-out  awscli              colorama  numpy            requests    torch  botocore            docutils  pyasn1           rsa         typing-extensions  certifi             idna      python-dateutil  s3transfer  urllib3  charset-normalizer  jmespath  pyyaml           six+ 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

Customization of and integration into existing development environments

Given an existing definition of a development environment using e.g.mkShell instead ofmkDerivation:

letnixpkgs=builtins.fetchTarball{# nixpkgs-unstable (2021-10-28)url="https://github.com/NixOS/nixpkgs/archive/22a500a3f87bbce73bd8d777ef920b43a636f018.tar.gz";sha256="1rqp9nf45m03mfh4x972whw2gsaz5x44l3dy6p639ib565g24rmh";};in{pkgs ?importnixpkgs{}}:pkgs.mkShell{nativeBuildInputs=withpkgs;[cmakegdbninjaqemu]++(withllvmPackages_13;[clangclang-unwrappedlldllvm]);hardeningDisable=["all"];}

you can integrate thePython On Nix development environment seamlessly via e.g.

letnixpkgs=builtins.fetchTarball{# nixpkgs-unstable (2021-10-28)url="https://github.com/NixOS/nixpkgs/archive/22a500a3f87bbce73bd8d777ef920b43a636f018.tar.gz";sha256="1rqp9nf45m03mfh4x972whw2gsaz5x44l3dy6p639ib565g24rmh";};in{pkgs ?importnixpkgs{}}:letpythonOnNix=import(builtins.fetchGit{ref="main";rev="2e735762c73651cffc027ca850b2a58d87d54b49";url="https://github.com/on-nix/python";}){nixpkgs=pkgs;};env=pythonOnNix.python39Env{name="example";projects={"awscli"="latest";# You can add more projects here as you need# "a" = "1.0";# "b" = "2.0";# ...};};inpkgs.mkShell{nativeBuildInputs=[env.dev]++(withpkgs;[cmakegdbninjaqemu])++(withpkgs;withllvmPackages_13;[clangclang-unwrappedlldllvm]);hardeningDisable=["all"];}

Using with Nix unstable (Nix Flakes)

This project is also offered as a Nix Flake.

⚠️ This section is for advanced Nix users.You can skip its contentas Nix Flakes is currentlyanunstable release of Nix.

$ nix flake show github:on-nix/python

Trying out single projects

  • $ nix develop 'github:on-nix/python#"awscli-1.20.31-python39"'
  • $ nix develop 'github:on-nix/python#"pytest-latest-python37"'

Installing applications in your system

  • $ nix profile install 'github:on-nix/python#"awscli-1.20.31-python39-bin"'
  • $ nix profile install 'github:on-nix/python#"pytest-latest-python37-bin"'

Creating Python environments with many applications and libraries

# /path/to/my/project/flake.nix{inputs={flakeUtils.url="github:numtide/flake-utils";nixpkgs.url="github:nixos/nixpkgs";pythonOnNix.url="github:on-nix/python";pythonOnNix.inputs.nixpkgs.follows="nixpkgs";};outputs={self, ...} @inputs:inputs.flakeUtils.lib.eachSystem["x86_64-linux"](system:letnixpkgs=inputs.nixpkgs.legacyPackages.${system};pythonOnNix=inputs.pythonOnNix.lib.${system};# Pick the Python version of your choice:# - `python37Env`: Python 3.7# - `python38Env`: Python 3.8# - `python39Env`: Python 3.9# - `python310Env`: Python 3.10env=pythonOnNix.python39Env{name="example";projects={awscli="1.20.31";numpy="latest";requests="latest";torch="1.9.0";};};# `env` has two attributes:# - `dev`: The activation script for the Python on Nix environment# - `out`: The raw contents fo the Python site-packagesin{devShells={# The activation script can be used as dev-shellexample=env.dev;};});}

You can now launch the environment!

$ nix develop'.#example'

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

Also, you'll be able to use the applications and libraries providedby 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 usePython on Nix andNixpkgs together.

For example:

# /path/to/my/project/flake.nix{inputs={flakeUtils.url="github:numtide/flake-utils";nixpkgs.url="github:nixos/nixpkgs";pythonOnNix.url="github:on-nix/python";pythonOnNix.inputs.nixpkgs.follows="nixpkgs";};outputs={self, ...} @inputs:inputs.flakeUtils.lib.eachSystem["x86_64-linux"](system:letnixpkgs=inputs.nixpkgs.legacyPackages.${system};pythonOnNix=inputs.pythonOnNix.lib.${system};# Pick the Python version of your choice:# - `python37Env`: Python 3.7# - `python38Env`: Python 3.8# - `python39Env`: Python 3.9# - `python310Env`: Python 3.10env=pythonOnNix.python39Env{name="example";projects={awscli="1.20.31";numpy="latest";requests="latest";torch="1.9.0";};};# `env` has two attributes:# - `dev`: The activation script for the Python on Nix environment# - `out`: The raw contents fo the Python site-packagesin{packages=rec{something=nixpkgs.stdenv.mkDerivation{buildInputs=[env.dev];virtualEnvironment=env.out;builder=builtins.toFile"builder.sh"''              source $stdenv/setup              set -x              ls $virtualEnvironment              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              set +x            '';name="something";};};});}

Now just$ nix -L build .#something ! 🚀

+ ls /nix/store/...-example-out  awscli              colorama  numpy            requests    torch  botocore            docutils  pyasn1           rsa         typing-extensions  certifi             idna      python-dateutil  s3transfer  urllib3  charset-normalizer  jmespath  pyyaml           six+ python --version  Python 3.9.6+ aws --version  aws-cli/1.20.31 Python/3.9.6 Linux/5.10.62 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/dcccmxjllgwb9c9j6irp68f1qp4ssxyg-example

Contributing

Anything you can think of will be appreciated!

License

Code on this branch is dedicated to the public domainviaThe Unlicense license.

In other words you can do anything you want with it.

Please enjoy! 🚀



[8]ページ先頭

©2009-2025 Movatter.jp