Python: Difference between revisions
imported>Anduh |
imported>Enolan add a bit about buildFHSUserEnv |
||
| Line 137: | Line 137: | ||
pip install -r requirements.txt | pip install -r requirements.txt | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Installing packages with <code>pip</code> that need to compile code or use C libraries will sometimes fail due to not finding dependencies in the expected places. In that case you can use <code>buildFHSUserEnv</code> to make yourself a sandbox that appears like a more typical Linux install. For example if you were working with machine learning code you could use: | |||
<syntaxhighlight lang="nix"> | |||
{ pkgs ? import <nixpkgs> {} }: | |||
(pkgs.buildFHSUserEnv { | |||
name = "pipzone"; | |||
targetPkgs = pkgs: (with pkgs; [ | |||
python39 | |||
python39Packages.pip | |||
python39Packages.virtualenv | |||
cudaPackages.cudatoolkit_11 | |||
]); | |||
runScript = "bash"; | |||
}).env | |||
</syntaxhighlight> | |||
In <code>pip-shell.nix</code>, and enter the environment with: | |||
<syntaxhighlight lang="shell"> | |||
nix-shell pip-shell.nix | |||
virtualenv venv | |||
source venv/bin/activate | |||
</syntaxhighlight> | |||
=== Emulating virtualenv with nix-shell === | === Emulating virtualenv with nix-shell === | ||