How to install pip for make use of nixos.python38Full?

Hello people! It’s my first time typing here. So forgive me for any misconceptions.
I have installed the respective package, but I’m not found pip package compatible with this.
I’m learning to programme with this Learning Python by Building Games book.
They instruct me to install Python PyGame and PyOpenGL in a sequence (python3 > pip > pygame), where one depends on previous.

How I can do this on NixOS?

Thanks for any help you can give me.

pip is used as a package manager to install other packages. They say to install it because it’s needed only for the install of pygame. However, nixpkgs can just do this for you:

[15:00:27] jon@jon-workstation ~/projects/nixpkgs (master)
$ nix-shell -p python3Packages.pygame

[nix-shell:~/projects/nixpkgs]$ python
Python 3.7.6 (default, Dec 18 2019, 19:23:55)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>

however, that will only get you a single package, and you’re likely going to need a lot more than just pygame, please take a look at https://github.com/NixOS/nixpkgs/blob/a52195355312d2a9f5e71d4ff742bcc30c6f90ec/doc/languages-frameworks/python.section.md#how-to-consume-python-modules-using-pip-in-a-virtualenv-like-i-am-used-to-on-other-operating-systems- for using nixpkgs with virtualenv

1 Like

Thanks @jonringer. This solves my doubt sure!
But how I see on this video python environments on nix they fail a little. For example, this solution give me a different result for the python version.

[nix-shell:~]$ python
Python 3.7.5 (default, Oct 14 2019, 23:08:55) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
>>> 

I will try this certainly! Thanks for your help one more time @jonringer.

1 Like

it’s by design, I have my channels set to unstable, and I’m assuming you’re on stable. So there will be some divergence on package version. However, the principles are still the same in terms of nix :slight_smile:

This seems to be searched a lot for python usage with nixpkgs. I have since created a video demonstrating python packaging, and development workflow.

2 Likes

Thanks for the great video and excellent explanations! I’m still a bit unclear on something - in the video, you add install dependencies to the nix derivation as propagatedBuildInputs - but the build phase of buildPythonPackage runs the setuptools install on the package anyway which adds all the dependencies to the python environment. Is the point just to use nix packages wherever possible to avoid duplication and rebuilding? It seems really inconvenient to have to maintain two sets of dependency lists (one in setup.py and one in the default.nix. I guess mach-nix is trying to solve this problem?

Also, in your shell.nix you built a “development environment” but you didn’t install the package itself. A typical workflow would be to install all the dependencies including the code of the package you are developing, in editable mode. When I inspect my nix derivation, I see that my package installed this way is indeed installed in editable mode - so is this the default for anything residing on the local filesystem?

1 Like

correct, it’s meant to be a compromise between pip -e and nix.

but the build phase of buildPythonPackage runs the setuptools install on the package anyway which adds all the dependencies to the python environment

well, yes, but those dependencies need to be available in down stream packages, which is why they are propagated