我在default.nix中定义了以下环境:

with import <nixpkgs> {};
stdenv.mkDerivation rec {
  name = "env";
  env = buildEnv { name = name; paths = buildInputs; };
  buildInputs = [
    python35
    python35Packages.pyyaml
  ];
}

如果我运行nix-shellpython仍然是/usr/bin/python(在Ubuntu上运行)的系统python,而python3是指向Nix安装的python 3.5二进制文件的符号链接。有没有办法定义环境,使python指向Nix Python 3.5?

最佳答案

一个简单的解决方案是向您的环境添加一个shell钩子,定义一个从pythonpython3的别名。只有在运行nix-shell时,此别名才会处于活动状态:

with import <nixpkgs> {};
stdenv.mkDerivation rec {
  name = "env";
  env = buildEnv { name = name; paths = buildInputs; };
  buildInputs = [
    python35
    python35Packages.pyyaml
  ];
  # Customizable development shell setup
  shellHook = ''
    alias python='python3'
  '';
}

关于python - 如何定义默认为Python 3.5的Nix环境,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40008731/

10-12 19:24