Installing Python packages in isolated environments with pipx

Hi!,

Here a new enthusiastic Nix user :slight_smile:. After hearing about all the good things that immutable systems would bring to my developer life, I decided to start playing around with Nix, and specifically, with Home Manager.

So far, very happy with the results. As advised in multiple blogs, I started small, slowly migrating my Ansible playbook which contains most of the programs and configurations I have across machines.

Today I reached a new milestone: my Python development environment.

I use for development some tools like iptyhon or the esptool that are native Python packages, but that I like to keep independent of the System’s python environment, being installed and isolated in their own environment. This saves some trouble with potential incompatible library versions.

Currently, I do this via pipx. But I’m not sure how to use Nix and Pipx for installing the packages.

How can I install Python packages using pipx in a Nix file?

PD: Could be that I’m thinking “in the wrong direction”. If so, please take my thoughts in the right path :wink:

2 Likes

Did you find a solution to this in the end?

I do not install pipx via Nix. However, I install iPython as system wide tool as an aid if I need/want a Python REPL.

My Nix configuration is, for me, a way to keep some tools available system wide.

For my development projects, I like to use DevBox. It is also Nix based, and it uses the same local store than Nix. So, if I want to have a REPL that can access my local venv, I install it on the project with DevBox.

If a Python tool that I want to use is not available on the version I need via Nix packages, then I still install manually pipx in the machine and use it to install the Python library