diff options
Diffstat (limited to 'nixpkgs/doc/languages-frameworks/python.section.md')
-rw-r--r-- | nixpkgs/doc/languages-frameworks/python.section.md | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/nixpkgs/doc/languages-frameworks/python.section.md b/nixpkgs/doc/languages-frameworks/python.section.md index 88dc42ebc6c2..41a5dae8b9b0 100644 --- a/nixpkgs/doc/languages-frameworks/python.section.md +++ b/nixpkgs/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 @@ -593,7 +611,7 @@ as the interpreter unless overridden otherwise. All parameters from `stdenv.mkDerivation` function are still supported. The following are specific to `buildPythonPackage`: * `catchConflicts ? true`: If `true`, abort package build if a package name appears more than once in dependency tree. Default is `true`. -* `disabled` ? false: If `true`, package is not build for the particular Python interpreter version. +* `disabled` ? false: If `true`, package is not built for the particular Python interpreter version. * `dontWrapPythonPrograms ? false`: Skip wrapping of python programs. * `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment variable in wrapped programs. * `installFlags ? []`: A list of strings. Arguments to be passed to `pip install`. To pass options to `python setup.py install`, use `--install-option`. E.g., `installFlags=["--install-option='--cpp_implementation'"]`. @@ -803,6 +821,9 @@ should be used with `ignoreCollisions = true`. The following are setup hooks specifically for Python packages. Most of these are used in `buildPythonPackage`. +- `eggUnpackhook` to move an egg to the correct folder so it can be installed with the `eggInstallHook` +- `eggBuildHook` to skip building for eggs. +- `eggInstallHook` to install eggs. - `flitBuildHook` to build a wheel using `flit`. - `pipBuildHook` to build a wheel using `pip` and PEP 517. Note a build system (e.g. `setuptools` or `flit`) should still be added as `nativeBuildInput`. - `pipInstallHook` to install wheels. @@ -850,9 +871,8 @@ Note: There is a boolean value `lib.inNixShell` set to `true` if nix-shell is in Packages inside nixpkgs are written by hand. However many tools exist in community to help save time. No tool is preferred at the moment. -- [python2nix](https://github.com/proger/python2nix) by Vladimir Kirillov -- [pypi2nix](https://github.com/garbas/pypi2nix) by Rok Garbas -- [pypi2nix](https://github.com/offlinehacker/pypi2nix) by Jaka Hudoklin +- [pypi2nix](https://github.com/nix-community/pypi2nix): Generate Nix expressions for your Python project. Note that [sharing derivations from pypi2nix with nixpkgs is possible but not encouraged](https://github.com/nix-community/pypi2nix/issues/222#issuecomment-443497376). +- [python2nix](https://github.com/proger/python2nix) by Vladimir Kirillov. ### Deterministic builds @@ -1017,7 +1037,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"; @@ -1027,9 +1050,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 @@ -1042,14 +1064,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 ''; |