How to install python in project idx

Hi Pranay - one option is to create a Gemini API Notebook project:

This will create a Python-based notebook. To see how we provisioned this environment, you can look at the dev.nix file generated by it:

# 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.python311
    pkgs.python311Packages.pip
  ];
  # Sets environment variables in the workspace
  env = {};
  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      "ms-toolsai.jupyter"
      "ms-python.python"
    ];
    workspace = {
      # Runs when a workspace is first created with this `dev.nix` file
      onCreate = {
        create-venv = ''
          python -m venv .venv
          source .venv/bin/activate
          pip install -r requirements.txt
        '';
      };
      # To run something each time the environment is rebuilt, use the `onStart` hook
    };
    # Enable previews and customize configuration
    previews = {};
  };
}

These Nix settings are what tell the workspace to be setup with the Python libraries, command line tools, and so on. You could replicate this in your blank workspace by adding the missing details into that workspace’s dev.nix file.

Cheers,
Kirupa

2 Likes