You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NixOS环境下如何为Jupyter添加prophet依赖包?

在NixOS的JupyterWith中添加Prophet包时出现"undefined variable 'prophet'"错误的解决方法

问题背景

我在NixOS上使用JupyterWith框架构建声明式的可复现Jupyter环境,原本的shell.nix配置运行完全正常,但当我尝试添加prophet作为Python依赖项时,执行nix-shell命令时抛出了如下错误:

error: undefined variable 'prophet' at /home/jbezdek/shell.nix.jupyter:15:7 (use '--show-trace' to show detailed location information)

原配置文件如下:

let
  jupyter = import (builtins.fetchGit {
    url = https://github.com/tweag/jupyterWith;
    rev = "37cd8caefd951eaee65d9142544aa4bd9dfac54f";
  }) {};
  iPython = jupyter.kernels.iPythonWith {
    name = "python";
    packages = p: with p; [
      pandas
      numpy
      seaborn
      matplotlib
      scikitlearn
      # prophet
    ];
  };
  iHaskell = jupyter.kernels.iHaskellWith {
    extraIHaskellFlags = "--codemirror Haskell";
    name = "haskell";
    packages = p: with p; [ hvega formatting ];
  };
  jupyterEnvironment = jupyter.jupyterlabWith {
    kernels = [ iPython iHaskell ];
  };
in jupyterEnvironment.env

解决方法

这个错误的核心原因是:在你当前使用的JupyterWith版本对应的Nixpkgs集合中,Facebook Prophet的Python包对应的属性名称不是prophet,而是fbprophet。Nix在Python包集合里找不到名为prophet的变量,所以抛出了未定义的错误。

你只需要将配置中的prophet替换为fbprophet即可,修改后的Python依赖部分如下:

packages = p: with p; [
  pandas
  numpy
  seaborn
  matplotlib
  scikitlearn
  fbprophet
];

完整的修改后配置文件:

let
  jupyter = import (builtins.fetchGit {
    url = https://github.com/tweag/jupyterWith;
    rev = "37cd8caefd951eaee65d9142544aa4bd9dfac54f";
  }) {};
  iPython = jupyter.kernels.iPythonWith {
    name = "python";
    packages = p: with p; [
      pandas
      numpy
      seaborn
      matplotlib
      scikitlearn
      fbprophet
    ];
  };
  iHaskell = jupyter.kernels.iHaskellWith {
    extraIHaskellFlags = "--codemirror Haskell";
    name = "haskell";
    packages = p: with p; [ hvega formatting ];
  };
  jupyterEnvironment = jupyter.jupyterlabWith {
    kernels = [ iPython iHaskell ];
  };
in jupyterEnvironment.env

修改完成后重新执行nix-shell,应该就能正常构建包含Prophet的Jupyter环境了。

内容的提问来源于stack exchange,提问作者Jaroslav Bezděk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:34:07