Pandas is not working

This seems like it should be easy, but I cannot get pandas to work. I added these two lines to the “packages” section:

pkgs.python3Packages.pandas
pkgs.python3Packages.matplotlib

Then, I tried to run code that used the package. I’m getting an error: "No module named ‘pandas’ "

Thank you for the help!

Here is my code (csv file located next to main.py):

import pandas as pd
import matplotlib.pyplot as plt
df2 = pd.read_csv("formatdata.csv")
df2.boxplot()
plt.suptitle('Period 1 box plot')
plt.show()

Here is my dev.nix:

# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
  # Which nixpkgs channel to use.
  channel = "stable-23.11"; # or "unstable"
  # Use https://search.nixos.org/packages to find packages
  packages = [
    # pkgs.go
    # pkgs.python311
    # pkgs.python311Packages.pip
    # pkgs.nodejs_20
    # pkgs.nodePackages.nodemon
    pkgs.python4
    pkgs.python3Packages.pip
    pkgs.python3Packages.pandas
    pkgs.python3Packages.matplotlib
  ];
  # Sets environment variables in the workspace
  env = {};
  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      # "vscodevim.vim"
      "ms-python.python"
      "ms-python.debugpy"
    ];
    # Enable previews
    previews = {
      enable = true;
      previews = {
        # web = {
        #   # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
        #   # and show it in IDX's web preview panel
        #   command = ["npm" "run" "dev"];
        #   manager = "web";
        #   env = {
        #     # Environment variables to set for your server
        #     PORT = "$PORT";
        #   };
        # };
      };
    };
    # Workspace lifecycle hooks
    workspace = {
      # Runs when a workspace is first created
      onCreate = {
        # Example: install JS dependencies from NPM
        # npm-install = "npm install";
        # Open editors for the following files by default, if they exist:
        default.openFiles = [ ".idx/dev.nix" "README.md" ];
      };
      # Runs when the workspace is (re)started
      onStart = {
        # Example: start a background task to watch and re-build backend code
        # watch-backend = "npm run watch-backend";
      };
    };
  };
}

You need to do a pip install pandas for it to work… For that you need to first activate a python virtual environment and the install pandas then it will work

1 Like