我正在尝试使用 Nix 安装 DocArray 和 Jina Hubble SDK,但遇到循环依赖问题。具体来说,我需要安装 DocArray 才能继续安装 Jina Hubble SDK,但 Jina Hubble SDK 是安装 DocArray 的先决条件。
flake.nix
{ 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};
#Define Python package jina-hubble-sdk
jina-hubble-sdk = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "jina-hubble-sdk";
version = "0.39.0";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "9021417794a6d3cf3fad8a880cf668a3a986b9d53d5be5fa391aae1767a5b9b0";
};
preConfigure = ''
export HOME=$(mktemp -d)
'';
nativeBuildInputs = [
poetry-core
];
propagatedBuildInputs = [
opentelemetry-instrumentation-grpc
uvloop
aiofiles
websockets
pep517
pip
requests
aiohttp
rich
importlib-metadata
filelock
pathspec
docker
pyyaml
python-jose
];
};
# # Define Python package jcloud
jcloud = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "jcloud";
version = "0.3";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "dc062c0454041562476032768fc48f426cc40b8e2323d9626377ff44b0d6f3d9";
};
preConfigure = ''
export HOME=$(mktemp -d)
'';
nativeBuildInputs = [
poetry-core
];
propagatedBuildInputs = [
pip
rich
aiohttp
jina-hubble-sdk
packaging
pyyaml
python-dotenv
python-dateutil
#python-dateutil
#python-dotenv
#pyyaml
# Add any dependencies jcloud might have here
];
};
# Define Python package jina
jina = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "jina";
version = "3.24.0";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "91f7a6141f46884b87d011e64cbf053391d418289391c3c633b10f0c7942553b";
};
nativeBuildInputs = [
poetry-core
];
propagatedBuildInputs = [
pip
jcloud
# Add any dependencies jina might have here
];
};
# Define Python package docarray
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
];
};
# Define Python package vectordb
vectordb = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "vectordb";
version = "0.0.21";
src = pkgs.fetchPypi {
inherit pname version;
sha256 = "3f4857ed3f26dc2384415f28851526037058008156719ca0cfc208a9a02d88e8";
};
nativeBuildInputs = [
poetry-core
];
propagatedBuildInputs = [
pip
setuptools
docarray
jina
];
};
# Define Python environment with necessary packages
pythonEnv = pkgs:
pkgs.python3.withPackages (ps:
with ps; [
langchain-community
langchainplus-sdk
langchain
tiktoken
docarray
vectordb
jina # Include jina in the environment
jcloud # Include jcloud in the environment
]);
in {
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
curl
ollama
(pythonEnv pkgs)
];
};
}); }
如果在注释 docarray 上面的每个 python 包后运行 flake,则在运行 flake 时会收到此错误:
错误:
… while calling the 'derivationStrict' builtin
at /builtin/derivation.nix:9:12: (source not available)
… while evaluating derivation 'nix-shell'
whose name attribute is located at /nix/store/zaza7mgggz4m5h6z18kajabf4wciaj47-source/pkgs/stdenv/generic/make-derivation.nix:331:7
… while evaluating attribute 'buildInputs' of derivation 'nix-shell'
at /nix/store/zaza7mgggz4m5h6z18kajabf4wciaj47-source/pkgs/stdenv/generic/make-derivation.nix:378:7:
377| depsHostHost = elemAt (elemAt dependencies 1) 0;
378| buildInputs = elemAt (elemAt dependencies 1) 1;
| ^
379| depsTargetTarget = elemAt (elemAt dependencies 2) 0;
(stack trace truncated; use '--show-trace' to show the full trace)
error: undefined variable 'jina'
at /nix/store/9z9khfrsm3dx1jh55cw09zi36l6dg1q2-source/flake.nix:162:13:
161| vectordb
162| jina # Include jina in the environment
| ^
163| jcloud # Include jcloud in the environment
这意味着你必须安装jcloud。取消注释jcloud。错误消息表明您必须安装另一个软件包。因此,您需要取消更多注释,直到取消 jina-hubble-sdk 包的注释。你会得到这个错误
错误:构建器 '/nix/store/c4xggnbjhl6wj6w71c6nszzxx39iv93a-python3.11-jina-3.24.0.drv' 失败,退出代码为 1; 最后 10 行日志: > ir_d = dist.fetch_build_eggs(dist.install_requires) > 警告:当前用户不拥有或不可写入目录“/homeless-shelter/.cache/pip”或其父目录。 缓存已被禁用。检查该权限和所有者 目录。如果使用 sudo 执行 pip,则应该使用 sudo 的 -H 标志。 > 警告:连接中断后重试(重试(总计=4,连接=无,读取=无,重定向=无,状态=无)) 'NewConnectionError('
: 无法建立新连接: [Errno -3] 名称解析暂时失败')': /simple/docarray/ > 警告:连接中断后重试(重试(总计=3,连接=无,读取=无,重定向=无,状态=无)) 'NewConnectionError(' : 无法建立新连接: [Errno -3] 名称解析暂时失败')': /simple/docarray/ > 警告:连接中断后重试(重试(总计=2,连接=无,读取=无,重定向=无,状态=无)) 'NewConnectionError(' : 无法建立新连接: [Errno -3] 名称解析暂时失败')': /simple/docarray/ > 警告:连接中断后重试(重试(总计=1,连接=无,读取=无,重定向=无,状态=无)) 'NewConnectionError(' : 无法建立新连接: [Errno -3] 名称解析暂时失败')': /simple/docarray/ > 警告:连接中断后重试(重试(总计=0,连接=无,读取=无,重定向=无,状态=无)) 'NewConnectionError(' : 无法建立新连接: [Errno -3] 名称解析暂时失败')': /simple/docarray/ > 错误:找不到满足要求 docarray>=0.16.4 的版本(来自版本:无) > 错误:找不到 docarray>=0.16.4 的匹配分布 >错误:命令'['/nix/store/3v2ch16fkl50i85n05h5ckss8pxx6836-python3-3.11.8/bin/python3.11', '-m', 'pip', '--disable-pip-version-check', 'wheel', '--no-deps', '-w'、'/build/tmp0nl2c1kv'、'--quiet'、'docarray>=0.16.4']' 返回 非零退出状态 1。 对于完整日志,请运行“nix log /nix/store/c4xggnbjhl6wj6w71c6nszzxx39iv93a-python3.11-jina-3.24.0.drv”。 错误:1 推导的依赖关系 '/nix/store/gw13rrga3q9mfsyly7lksmqpz85b81gd-python3-3.11.8-env.drv' 构建失败错误:1 派生依赖项 “/nix/store/81jdcd1la69iry4f83cgwhim27gvnvsb-nix-shell-env.drv”失败 建造
这意味着你必须安装docarray。如何解决这个循环依赖问题
重构你的 flake.nix:
使用延迟加载:
{
# ... other parts of your flake.nix
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
# Define Python packages
jina-hubble-sdk = with pkgs.python3Packages;
buildPythonPackage rec {
# ... jina-hubble-sdk definition
};
jcloud = with pkgs.python3Packages;
buildPythonPackage rec {
# ... jcloud definition
};
docarray = with pkgs.python3Packages;
buildPythonPackage rec {
# ... docarray definition
};
vectordb = with pkgs.python3Packages;
buildPythonPackage rec {
# ... vectordb definition
};
# Define jina with explicit dependencies (excluding docarray)
jina = with pkgs.python3Packages;
buildPythonPackage rec {
pname = "jina";
version = "3.24.0";
# ... other jina definition
propagatedBuildInputs = [
pip
# Add explicit dependencies required by jina (excluding docarray)
];
};
# Define Python environment with necessary packages
pythonEnv = pkgs:
pkgs.python3.withPackages (ps:
with ps; [
langchain-community
langchainplus-sdk
langchain
tiktoken
docarray
vectordb
]);
in {
# ... other parts
});
}
在此方法中,您定义
jina
及其直接依赖项并排除 docarray
。然后,您的环境(pythonEnv
)仅包含您需要的核心包。在应用程序中使用 jina
时,您可以使用 pip
以及任何缺少的依赖项(例如 docarray
)来安装它。