Theodora
Theodora

Reputation: 588

using nix-flakes on MBP, cannot import scipy

The idea of Nix is great and this is the third time in the past 10 years I tried to use Nix, hopefully, this time this strange issue could be solved!

I just started using Nix-flakes following this tutorial on my macbook

mkdir nix-python-dev && cd nix-python-dev
nix flake init --template "github:DeterminateSystems/zero-to-nix#python-dev"

then I edited the flake.nix file following this template, and here is my flake.nix file

description = "Example Python development environment for Zero to Nix";

  # Flake inputs
  inputs = {
    nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.2305.491812.tar.gz";
  };

  # Flake outputs
  outputs = { self, nixpkgs }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
        "aarch64-linux" # 64-bit ARM Linux
        "x86_64-darwin" # 64-bit Intel macOS
        "aarch64-darwin" # 64-bit ARM macOS
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
    {
      # Development environment output
      devShells = forAllSystems ({ pkgs }: {
        default =
          let
            # Use Python 3.11
            python = pkgs.python311;
          in
          pkgs.mkShell {
            # The Nix packages provided in the environment
            packages = [
              # Python plus helper tools
              (python.withPackages (ps: with ps; [
                virtualenv # Virtualenv
                pip # The pip installer
                scipy
                pandas
                csvw
              ]))
            ];
          };
      });
    };
}

Now everything works fine in the nix develop environment, I can import numpy, pandas, scipy, no problem.

HOWEVER, when I tried to use vscode, funny things happened. enter image description here I cannot import scipy.

The interpreter I'm using is this: enter image description here

Also, I noticed that now I could import numpy and pandas from any newly initiated python project following the same procedure described above, but DONOT need to add numpy and pandas in the flake.nix file.

WHY ? !

Upvotes: 0

Views: 55

Answers (1)

Theodora
Theodora

Reputation: 588

for some reason, I tried to select a new interpreter in 10 mins, and it now works fine.

I still have no idea why there is an interpreter labelled as Global and why it works...

I created a new project and tried importing lightgbm and starting a conda environment, but it failed again.

I think I will just give up Nix again this time . ...

Upvotes: 0

Related Questions