diff options
Diffstat (limited to 'doc/languages-frameworks/python.section.md')
-rw-r--r-- | doc/languages-frameworks/python.section.md | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/doc/languages-frameworks/python.section.md b/doc/languages-frameworks/python.section.md index 02bff8666e2..9cb0e1eecc1 100644 --- a/doc/languages-frameworks/python.section.md +++ b/doc/languages-frameworks/python.section.md @@ -144,6 +144,24 @@ What's happening here? 2. Then we create a Python 3.5 environment with the `withPackages` function. 3. The `withPackages` function expects us to provide a function as an argument that takes the set of all python packages and returns a list of packages to include in the environment. Here, we select the packages `numpy` and `toolz` from the package set. +To combine this with `mkShell` you can: + +```nix +with import <nixpkgs> {}; + +let + pythonEnv = python35.withPackages (ps: [ + ps.numpy + ps.toolz + ]); +in mkShell { + buildInputs = [ + pythonEnv + hello + ]; +} +``` + ##### Execute command with `--run` A convenient option with `nix-shell` is the `--run` option, with which you can execute a command in the `nix-shell`. We can @@ -1016,7 +1034,10 @@ Create this `default.nix` file, together with a `requirements.txt` and simply ex ```nix with import <nixpkgs> {}; -with python27Packages; + +let + pythonPackages = python27Packages; +in stdenv.mkDerivation { name = "impurePythonEnv"; @@ -1026,9 +1047,8 @@ stdenv.mkDerivation { buildInputs = [ # these packages are required for virtualenv and pip to work: # - python27Full - python27Packages.virtualenv - python27Packages.pip + pythonPackages.virtualenv + pythonPackages.pip # the following packages are related to the dependencies of your python # project. # In this particular example the python modules listed in the @@ -1041,14 +1061,13 @@ stdenv.mkDerivation { libxml2 libxslt libzip - stdenv zlib ]; shellHook = '' # set SOURCE_DATE_EPOCH so that we can use python wheels SOURCE_DATE_EPOCH=$(date +%s) - virtualenv --no-setuptools venv + virtualenv --python=${pythonPackages.python.interpreter} --no-setuptools venv export PATH=$PWD/venv/bin:$PATH pip install -r requirements.txt ''; |