Since Python version changes are far and few between, I always forget how I have created a new Conda environment with the latest Python for Jupyter Notebook, so I thought I'd list it down for next time. From StackOverflow, there are some answers that no longer worked, and below is a compilation of commands I found on StackOverflow that worked for me, Nov-29-2022. These instructions below are for Windows, and using Powershell (although they can also be used for the normal command line cmd.exe)
# make sure you are in the base env
# update conda
conda update conda
# to allow support for powershell
conda init --all
# The conda-forge repository seems to have at least the latest
# stable Python version, so we will get Python from there.
# add conda-forge to channels of conda.
conda config --add channels conda-forge
conda update jupyter
# to fix 500 internal server error when trying to open a notebook later
pip3 install --upgrade --user nbconvert
# nb_conda_kernels enables a Jupyter Notebook or JupyterLab
# application in one conda environment to access kernels for Python,
# R, and other languages found in other environments.
conda install nb_conda_kernels
# I will now create a new conda env for Python 3.11 and name it as Python3.11
conda create -n python3.11 python=3.11
# check that it was created
conda info --envs
conda activate python3.11
# Once installed, need to install ipykernel so Jupyter notebook can
# see the new environment python3.11.
conda install -n python3.11 ipykernel
# install ipywidgets as well for some useful functionalities
conda install -n python3.11 ipywidgets
# Since I use R too, I'll also add a note here on R
# To utilize an R environment, it must have the r-irkernel package; e.g.
# conda install -n r_env r-irkernel
# example to install a package in the new env, if desired
# conda install --update-all --name python3.11 numpy
#conda list will show the env's packages, versions, and where they came from too
conda activate python3.11
conda list
conda deactivate
# Now to check if the new environment can be selected in Jupyter
# Notebook. I change to the root directory first so jupyter
# notebook can see every folder. Note that we are in base
# environment, although no problem if in another environment
cd\
jupyter notebook
# If I open an existing notebook for example, I can tap on Kernel,
# then Change kernel, and I should now be able to select the kernel
# from the new environment I created, shown as "Python [conda env:python3.11]".
#
# There will also be another entry showing just the name of the env,
# in this case, python3.11. Just ignore this, select the entries
# starting with "Python [conda env" ...
#
# If I tapped on New instead when Jupyter Notebook opened, it will
# also show the list of envs.
# to check version, either use :
!python --version
# or
from platform import python_version
print(python_version())
# both will show the Python version of whatever kernel is in use
# by Jupyter notebook
# to test Python 3.10 or 3.11 for example... from 3.10, an optional
# strict parameter for zip has been added and can be used to
# generate an error if lists' lengths are not the same
a = [1,2,3,4]
b = ['a', 'b', 'c']
for val1, val2 in zip(a,b, strict = True):
print(val1, val2)
# this should appear - ValueError: zip() argument 2 is shorter than argument 1
Is there another way ?