Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup global python environment properly with nix

I'm getting familiar with nix by using it instead of brew on my Mac. I like it pretty much so far, but there is an issue with python environment. I can't figure out how to configure it properly.

I'm using powerline status, which is a python package itself, but also available as derivation (nixpkgs.python37Packages.powerline). So, I installed it together with python and some other packages:

# file: python.nix
with import <nixpkgs> {};
python3.withPackages (ps: with ps; [ pip pipenv powerline ipython ])

This is working as expected.

However, I'm also using some additional segments for powerline (ex. powerline-gitstatus), which are not available as derivations. So, I just installed them via pip install --user .... And then set PYTHONPATH=$HOME/.local/lib/python3.7/site-packages.

This is also working.

Apart from that I need to have awscli, which is a python package and available as standalone derivation (not nixpkgs.python37Packages.awscli), so I can't install it as a part of my custom python derivation, as far as I understand.

I tried to get it with nix-env -i awscli, but it didn't work together with set PYTHONPATH.

I tried to get it with pip install --user awscli, but it didn't work also.

In both cases it crashed because of lack of dependencies or version incompatibilities.

So, my question is: how to setup global python environment properly with nix?

like image 856
German Lashevich Avatar asked Jul 01 '26 02:07

German Lashevich


1 Answers

I guess following well-documented very convenient approach could help in your case also.

How to consume python modules using pip in a virtualenv like I am used to on other Operating Systems ?

10.09.2020 Update:
Developing Python with Poetry & Poetry2nix: Reproducible flexible Python environments describes an other working with python on NixOS approach.

like image 173
palik Avatar answered Jul 03 '26 16:07

palik