为什么尝试构建此 python 包会返回“后端 'poetry.core.masonry.api' 不可用”

问题描述 投票:0回答:1

不幸的是,python 包 docarray 在 nix 包管理器中不可用。因此我尝试自己构建它。

这个网站帮助我使用了

pkgs.python3Packages.buildPythonPackage
,我在这个网站

中得到了sha256
{
  description = "Python environment with ollama";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        python = pkgs.python311;
        ollama = pkgs.ollama;
        docarray = pkgs.python3Packages.buildPythonPackage rec {
          pname = "docarray";
          version = "0.40.0";
          format = "pyproject"; # Specify the package format
          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "c3f3b88b7b6128c10308dddbd21650c9845e270da850cf6718cb1d3d867d5986"; # TODO
      };
          #code proposed by phind (something like chatgpt) but it didn't help. Therefore it is commented
          # Add Poetry to the build inputs
          #buildInputs = [ pkgs.poetry ];
          # Add any runtime dependencies here
          #propagatedBuildInputs = [];
          # Add any Python package metadata here
          #meta = with pkgs.lib; {
          #  homepage = "https://github.com/docarray/docarray";
          #  description = "A Python package for managing document arrays";
          #  license = licenses.mit;
          #};
        };

        Py = python.withPackages (ps: with ps; [
            langchain-community
            langchainplus-sdk
            langchain
            tiktoken
            docarray
        ]);
      in {
        devShells.default = pkgs.mkShell {
          buildInputs = [
            pkgs.curl
            ollama
            Py
          ];
        };
      });
}

之后

running nix develop
我收到此错误消息

错误:构建器 '/nix/store/0dq2bsq9zkgmp845l2ncqkk2i9p1pqlm-python3.11-docarray-0.40.0.drv' 失败,退出代码为 1; 最后 10 行日志: > 文件“”,第 1204 行,在 _gcd_import 中 > 文件“”,第 1176 行,位于 _find_and_load 中 > 文件“”,第 1126 行,在 _find_and_load_unlocked 中 > 文件“”,第 241 行,在 _call_with_frames_removed 中 > 文件“”,第 1204 行,在 _gcd_import 中 > 文件“”,第 1176 行,位于 _find_and_load 中 > 文件“”,第 1140 行,在 _find_and_load_unlocked 中 > ModuleNotFoundError:没有名为“诗歌”的模块 > > 错误后端“poetry.core.masonry.api”不可用。 对于完整日志,请运行“nix-store -l /nix/store/0dq2bsq9zkgmp845l2ncqkk2i9p1pqlm-python3.11-docarray-0.40.0.drv”。 错误:1 推导的依赖关系 '/nix/store/rqg7i9w02fmbxqf2c4i3gz16icsx7q68-python3-3.11.8-env.drv' 构建失败错误:1 派生依赖项 “/nix/store/qxx83jf2n4l8zchdwagg6wsk4pz439v7-nix-shell-env.drv”失败 建造

python-poetry nix nix-flake
1个回答
0
投票

您需要将

poetry-core
添加到构建输入 (
nativeBuildInputs
) 才能在构建环境中安装 Poetry。然后你必须在
propagatedBuildInputs
中指定包依赖:

{
  description = "Python environment with ollama";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      docarray = with pkgs.python3Packages;
        buildPythonPackage rec {
          pname = "docarray";
          version = "0.40.0";
          format = "pyproject";

          src = pkgs.fetchPypi {
            inherit pname version;
            sha256 = "c3f3b88b7b6128c10308dddbd21650c9845e270da850cf6718cb1d3d867d5986";
          };

          nativeBuildInputs = [
            poetry-core
          ];

          propagatedBuildInputs = [
            numpy
            orjson
            pydantic
            rich
            types-requests
            typing-inspect
          ];
        };

      pythonEnv = pkgs:
        pkgs.python3.withPackages (ps:
          with ps; [
            langchain-community
            langchainplus-sdk
            langchain
            tiktoken
            docarray
          ]);
    in {
      devShells.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          curl
          ollama

          (pythonEnv pkgs)
        ];
      };
    });
}
© www.soinside.com 2019 - 2024. All rights reserved.