I’m doing my homework for a class in Uni, and it needs a fancy new library called plotnine. This lib doesn’t exist in nixpkgs yet, and I’d rather not have to bother fixing that (I have no experience actually creating derivations).
According to this github post, I can just set up a pyenv using pip itself to install the packages, which bypasses the need to nixify a niche python lib.
So I adapted that (slightly) to my needs, and wrote this default.nix:
with import <nixpkgs> {};
let
pythonPackages = python310Packages;
in
stdenv.mkDerivation {
name = "impurePythonEnv";
src = null;
buildInputs = [
# these packages are required for virtualenv and pip to work:
#
pythonPackages.virtualenv
pythonPackages.pip
# the following packages are related to the dependencies of your python
# project.
graphviz
ffmpeg
# These work when I pull them from nixpkgs, but not when I use the requirements.txt
pythonPackages.matplotlib
];
shellHook = ''
# set SOURCE_DATE_EPOCH so that we can use python wheels
SOURCE_DATE_EPOCH=$(date +%s)
virtualenv --python=${pythonPackages.python.interpreter} --no-setuptools venv
export PATH=$PWD/venv/bin:$PATH
#export PYTHONPATH=$PWD/venv/lib/python3.10/site-packages/:$PYTHONPATH
pip install -r requirements.txt
'';
}
I also set up a requirements.txt:
graphviz >= 0.20.0
networkx >= 2.8.0
matplotlib >= 3.6.0
numpy >= 1.23.0
plotnine >= 0.10.0
So, I was hoping I could use that to get pypi packages directly, and it almost worked (they installed without error) but when I try to run it I get this error:
Traceback (most recent call last):
File "/home/<USER>/Documents/<CLASS>/homework6/homework6.py", line 14, in <module>
from plotnine import *
File "/home/<USER>/Documents/<CLASS>/homework6/venv/lib/python3.10/site-packages/plotnine/__init__.py", line 1, in <module>
from .qplot import qplot # noqa: F401
[SNIP]
File "/home/<USER>/Documents/<CLASS>/homework6/venv/lib/python3.10/site-packages/palettable/colorbrewer/colorbrewer.py", line 7, in <module>
from pkg_resources import resource_string
ModuleNotFoundError: No module named 'pkg_resources'
What gives?