To create a new environment with a specific Python version and be able to use Jupyter and Spyder from that environment (while Jupyter and Spyder are installed in your base environment), follow these detailed steps:

Step 1: Create a New Conda Environment with a Specific Python Version

  1. Open your terminal in WSL2 (or use Anaconda Prompt if on Windows).

  2. Create a new Conda environment by running the following command. Replace my_env with your desired environment name and 3.8 with your preferred Python version:

    conda create --name my_env python=3.8
    
  3. Confirm the installation of the packages when prompted by typing y and pressing Enter.

Step 2: Activate the New Environment

  1. Once the environment is created, activate it by running:

    conda activate my_env
    
  2. Your terminal prompt should now show (my_env), indicating that the environment is active.

Step 3: Install spyder-kernels in the New Environment

  1. Since Spyder is already installed in the base environment, you only need to install spyder-kernels in the new environment:

    conda install spyder-kernels
    
  2. spyder-kernels is required for Spyder to connect to the new environment and execute code, debug, and use features like the variable explorer.

Step 4: Set Up the New Environment as a Jupyter Kernel

  1. To use Jupyter Notebook from your base environment with the new environment’s packages and Python version, you need to install ipykernel in the new environment:

    conda install ipykernel
    
  2. After installing ipykernel, register the new environment as a kernel in Jupyter:

    python -m ipykernel install --user --name=my_env --display-name "Python (my_env)"
    

Step 5: Launch Jupyter and Use the New Environment

  1. Launch Jupyter Notebook from the base environment:

    jupyter notebook
    
  2. In the Jupyter Notebook interface, go to Kernel -> Change Kernel and select Python (my_env).

  3. Now, any code you run in this notebook will use the packages and Python version specific to my_env.

Step 6: Use Spyder with the New Environment