I’m trying to get a Python virtualenv in which I could install some packages. Now I know that’s not the recommended way of doing things with Nix, but virtualenvs are very useful when locally developing packages that are not yet packaged in Nix.
I need to use an old Python version (3.5), so I used the following shell.nix
file, hoping it would allow me to create a virtualenv and install the requirements:
let
oldPkgs = import (builtins.fetchGit {
name = "python35-nixpkgs";
url = "https://github.com/NixOS/nixpkgs/";
ref = "refs/heads/nixos-20.03";
rev = "0cf6a5035932023c324bfda301b89190801c3f30";
}) {};
pkgs = import (builtins.fetchGit {
url = "/home/sephi/projects/nixpkgs";
ref = "origin/release-20.09";
rev = "e716ddfac4be879ffbae75c3914a538dd5d4d12e";
}) { };
python =
oldPkgs.python35.withPackages (ps: [ ps.pillow ps.isort ps.pyls-isort ]);
in pkgs.mkShell {
buildInputs = [
python
pkgs.nodejs-10_x
];
}
nix-shell
correctly drops me in a shell with Python 3.5 installed, and I can create a virtualenv using python -m venv /tmp/venv
. But this virtualenv doesn’t have pip installed (even if I add ps.pip
to my python35 package), and trying to install it using ensurepip
doesn’t work because it tries to install pip
in the nix store:
$ /tmp/venv/bin/python -m ensurepip
Requirement already satisfied: setuptools in /nix/store/w364k4rsaqwycb74wpldm7mxhppjdpqp-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg
Collecting pip
Installing collected packages: pip
Exception:
Traceback (most recent call last):
...
OSError: [Errno 30] Read-only file system: '/nix/store/z4f5y7hgpkdq66312kmjfphv57v9qlh0-python3-3.5.7/lib/python3.5/site-packages/pip-9.0.1.dist-info'
Setting --root
seems to work:
$ /tmp/venv/bin/python -m ensurepip --root /tmp/venv/
Requirement already satisfied: setuptools in /nix/store/w364k4rsaqwycb74wpldm7mxhppjdpqp-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg
Collecting pip
Installing collected packages: pip
Successfully installed pip-9.0.1
But the package gets installed in /tmp/venv/nix/store/z4f5y7hgpkdq66312kmjfphv57v9qlh0-python3-3.5.7/lib/python3.5/site-packages/pip
.
Does anyone know how I can get pip installed in the virtualenv, so I can try installing the Python requirements (which I suspect will fail, but I couldn’t even try that yet ^^)? Or do you have an idea how I could do it differently (without having to package each dependency of the requirements.txt
file)? I know there are some *2nix tools out there, but the one I had the most success (or rather, the least failures) with doesn’t support editable requirements (-e git+https://...
).