Search code examples
python-3.xdevelopment-environmentnixopenai-api

Nix openai python dev-environment build failure


I am trying to make a python37 development environment containing the openai pypi package using nix.

This question was originally on reddit, but I couldn't find an answer and the activity in the thread was very low.

using the tipps i got there and the language frameworks documentation i managed to come up with the following expressions:

default.nix:

with import<nixpkgs>{};
( let
    openai = pkgs.callPackage ./release.nix {
              inherit pkgs; 
              buildPythonPackage = pkgs.python37Packages.buildPythonPackage;
            };
  in pkgs.python37.buildEnv.override rec {
    extraLibs = [ pkgs.python37Packages.requests openai ];
  }
).env

release.nix

{ pkgs, buildPythonPackage }:

buildPythonPackage rec{
  pname="openai";
  version="0.2.6";

  src=fetchTarball{
    url="https://files.pythonhosted.org/packages/59/2d/b3bc2aa663b2c376f073fd141e128ecfb47f3aff95ccee284a74d85a1ef8/openai-0.2.6.tar.gz";
    sha256="0cplrzfw3i6yxcd35ijfjkx9jbcvkvzn5jn5b8s657a8myhm6kav";
  };

  propagateBuildInputs = [ pkgs.python37Packages.requests ];
  doCheck=false;

  meta = { # only for testing the env right now
    homepage="...";
    description="...";
    license = "...";
    maintainers= [];
  };
}

however, this leaves me with the (i guess its pip-)error

Processing ./openai-0.2.6-py3-none-any.whl
ERROR: Could not find a version that satisfies the requirement requests>=2.20; python_version >= "3.0" (from openai==0.2.6) (from versions: none)
ERROR: No matching distribution found for requests>=2.20; python_version >= "3.0" (from openai==0.2.6)
builder for '/nix/store/ncnga4fcxl15xyvv3f325f9g0q45mqvr-python3.7-openai-0.2.6.drv' failed with exit code 1

which surprises me, because propagateBuildInputs = [ pkgs.python37Packages.requests ]; clearly states that the package requests (version 2.22.0 in nixpkgs) should be present at build time.

what am I misunderstanding about the buildPythonPackage function that prevents this from working?


Solution

  • Changing progagatedBuildInputs to another name like progagateBuildInputs causes it to be ignored, so any dependencies it contains (i.e. requests) are not found. For example:

    yubico-client/default.nix
    
      propagateBuildInputs = [ requests ];
    
    ERROR: Could not find a version that satisfies the requirement requests<3.0,>=2.7 (from yubico-client==1.13.0) (from versions: none)
    ERROR: No matching distribution found for requests<3.0,>=2.7 (from yubico-client==1.13.0)
    
      propagatedBuildInputs = [ requests ];
    
    $ nix-build -I nixpkgs=~/git/nixpkgs '<nixpkgs>' -k -A python37Packages.yubico-client
    /nix/store/0yjz8smgmjr0006nmka6wliy01z8av7m-python3.7-yubico-client-1.13.0