How to install python in project idx

I am a new project IDX, and I have created an empty project. I was trying to have a Python notebook and just run Hello World. But for the love of god, I can’t install Python in this environment. Any help is appreciated, and thank you.

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

1 Like

Awesome thank you so much for letting me know and I will give it a try now and let you know the progress

So basically I did this but I was not able to install pip packages

@Hemansh_Patel guessing that you used python3.xx<11 or 12 .
I faced this issue also, but there’s a fix, just do this

python3.X -m pip install bla bla #where X is the python version, -m means message

for some weird reason it shows “No module named pip”

  1. Try clicking the run button instead, I don’t think you’re inside the virtualenv, so you can’t access some of the installed module.
    Alternatively, you can run source .venv/bin/activate in the terminal before running the python program (or before running pip)

  2. Pygame will not work on IDX as there are no way to stream native application for the time being
    Pygame/PySimpleGUI setup help - #6 by kirupa