Python: Difference between revisions
imported>Krey No edit summary |
imported>Danbst No edit summary |
||
| Line 43: | Line 43: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Emulating virtualenv with nix-shell === | |||
In some cases virtualenv fails to install a library because it requires patching on NixOS (example 1, example 2, general issue). In this cases it is better to replace those libraries with ones from Nix. | |||
Let's say, that nanomsg library fails to install in virtualenv. Then write a `default.nix` file: | |||
<syntaxhighlight lang="nix"> | |||
let pkgs = import <nixpkgs> {}; | |||
nanomsg-py = .... build expression for this python library; | |||
in pkgs.stdenv.mkShell { | |||
buildInputs = [ | |||
pkgs.pythonPackages.pip | |||
nanomsg-py | |||
]; | |||
shellHook = '' | |||
alias pip="PIP_PREFIX='$(pwd)/_build/pip_packages' \pip" | |||
export PYTHONPATH="$(pwd)/_build/pip_packages/lib/python2.7/site-packages:$PYTHONPATH" | |||
unset SOURCE_DATE_EPOCH | |||
''; | |||
} | |||
</syntaxhighlight> | |||
After entering the environemnt with `nix-shell`, you can install new python libraries with dump `pip install`, but nanomsg will be detected as installed. | |||
=== conda === | === conda === | ||