如何使用默认值.nix文件?

2024-06-26 02:24:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道尼克斯是怎么工作的。为此,我尝试创建一个简单的环境来运行jupyter笔记本电脑。在

当我运行命令时:

nix-shell -p "\
    with import <nixpkgs> {};\
    python35.withPackages (ps: [\
        ps.numpy\
        ps.toolz\
        ps.jupyter\
    ])\
    "

我得到了我所期望的——在一个安装了python和列出的所有包的环境中的一个shell,以及在路径中可以访问的所有预期命令:

^{pr2}$

因此,我用一个default.nix文件创建了一个新文件夹,其中包含以下内容:

with import <nixpkgs> {};

python35.withPackages (ps: [
  ps.numpy 
  ps.toolz
  ps.jupyter
])

但是,当我在这个文件夹中运行nix-shell时,似乎所有的东西都安装好了,但是没有设置{}:

[nix-shell:~/dev/hurricanes]$ which python
/usr/bin/python

[nix-shell:~/dev/hurricanes]$ which jupyter

[nix-shell:~/dev/hurricanes]$ jupyter
The program 'jupyter' is currently not installed. You can install it by typing:
sudo apt install jupyter-core

我认为这两种情况是等价的。我做错什么了?在


Tags: devimport命令numpy环境withnixjupyter
1条回答
网友
1楼 · 发布于 2024-06-26 02:24:32

当使用nix-build调用时,default.nix文件应该包含生成派生的信息。当用nix-shell调用它时,它只是以一种可以构建派生的方式设置shell。{cd4>中列出的所有属性都包含在属性中:

with import <nixpkgs> {};

stdenv.mkDerivation {

  name = "my-env";

  # src = ./.;

  buildInputs =
    python35.withPackages (ps: [
      ps.numpy 
      ps.toolz
      ps.jupyter
    ]);

}

在这里,我已经注释掉了src属性,如果您想运行nix-build,那么这个属性是必需的,但是当您正在运行nix-shell时,这个属性是不必要的。在

在你最后一句话中,我想你指的是更确切地说: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/python.section.md#load-environment-from-nix-expression 我不明白这个建议:在我看来,这完全是假的。在

相关问题 更多 >