我正在尝试使用nix创建一个包含openai
pypi包的python37开发环境。
这个问题最初是在reddit上提出的,但我找不到答案,而且该帖子的活跃度非常低。
根据我在那里的提示和语言框架的文档,我设法编写了以下表达式:
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= []; };}
然而,这让我遇到了(我猜是pip的)错误
Processing ./openai-0.2.6-py3-none-any.whlERROR: 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
这让我感到惊讶,因为propagateBuildInputs = [ pkgs.python37Packages.requests ];
明确指出,包requests
(在nixpkgs中的版本为2.22.0)应该在构建时存在。
我对buildPythonPackage
函数的理解有什么误解,导致它无法正常工作?
回答:
将progagatedBuildInputs
更改为其他名称,如progagateBuildInputs
,会导致它被忽略,因此其中包含的任何依赖项(即requests
)都不会被找到。例如:
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