N.B. last tested successfully onSepotember 27th, 2022.
I love JupyterLab, I really do! In my experience to date it proved to be the best environment for prototyping scientific computing applications interactively using Jupyter notebooks.
If you wonder if this is the right tool for you, please browse the rich documentation on the JupyterLab Interface and on how to work with Notebooks, then make sure to watch the 2018 Scipy tutorial. I guarantee that if you’ve been working with Jupyter notebooks and liked them, you will easily switch to JupyterLab and will never look back, it is only natural (also check Terraforming Jupyter to get a flavor of how much you can customize this environment to suit your needs).
Three times in the last couple of months I’ve had to make an installation from scratch on Windows 10 operated computers, using the Anaconda Python distribution: for a coworker’s desktop computer and my own, and for a friend on a laptop.
I’ve decided to summarize in this post my installation, which includes setting up JupyterLab and also creating virtual environments. I am hoping that even an absolute beginner will be able to follow these instructions, and go from zero to JupyterLab pro.
Setting up JupyterLab with virtual environments on Windows 10
Step 1 – Download Anaconda
Go to the Ananaconda website for the Windows distribution and download the Python 3.8 installer:
NB: If you are one of those few still working with Python 2.7 (I was one until last fall), worry not, I will show you how to create a Python 2.7 virtual environment without much effort.
Step 2 – Install Anaconda
Follow the official installation instructions to the letter, with the exception of step 8. Here I would suggest especially if you want the ability to start JupyterLab from the command prompt, the alternative setting:
NB: I realize this is discouraged because it may cause interference with other software down the road, but I’ve found no issue yet (not a guarantee, of course, so do at your own peril), and it is much easier than having to add the path manually.
Step 3 – Set Chrome as web browser for JupyterLab
I’ve never been able to make JupyterLab work with Internet Explorer, so this is not an optional step for me. To set Chrome as the browser for JupyterLab, open the config file jupyter_notebook_config.py
(located in your home directory, in ~/.jupyter
), find the browser section:
then replace the last line, c.NotebookApp.browser = ''
, with:
c.NotebookApp.browser = '"C:/path/to/your/chrome.exe" %s'
for example:
‘”C:\Program Files\Google\Chrome\Application\chrome.exe” %s’
N.B. For mac users, use this:
c.NotebookApp.browser = 'open -a /Applications/Google\ Chrome.app %s'
If the config file is not present in the home directory, it can be created at the prompt with the command:
jupyter notebook --generate-config
In Windows, this will create the file at this location:
C:\Users\yourusername\.jupyter\jupyter_notebook_config.py
Step 4 – Install nb_condas_kernels
The package nb_conda_kernels will later detect all conda environments that have notebook kernels and automatically registers them. As a result, all those environments will be visible and can be used directly from the JupyterLab interface. So:
a) check if nb_conda_kernels
is installed by executing conda list
at the prompt.
b) If you do not see it in the list of packages, then execute conda install -c anaconda nb_conda_kernels
Step 5 – Edit the Conda configuration file to create environments with default packages
To automatically install specific packages every time a new environment is created, add the package list to the create_default_packages section of the.condarc
configuration file, which is located in the home directory. For example, in Windows, this would be:
C:\Users\yourusername\.condarc
If the .condarc
configuration file is not present, you can:
- download a sample from this page then edit it
- generate one using
conda config
, for example with:
conda config --add channels conda-forge
then edit it. The syntax for the file is the same used in environment files; here’s an example:
NB: ipykernel
is necessary if nb_conda_kernels
is to detect the environments.
If you’d prefer to install each package individually, you can install ipykernel
with:
conda install ipykernel
Step 6 – Create the desired environments
To create both Python 3.6 and a Python 2.7 environments, for example, execute at the prompt the two commands below:
conda create -n py37 python=3.7
conda create -n py27 python=2.7
Step 7 – Start JupyterLab
At the prompt, execute the command:
Jupyter lab
This will open the JupyterLab Interface automatically in Chrome. From there you can select File>New>Notebook and you will be prompted to select a Kernel as below, where you see that both environments just created are available:
Step 8 – Have fun
You are all set to work with the Notebooks in JupyterLab.
PS: To ensure the packages defined in the Conda configuration file were included in both environments, I run this example from the Seaborn tutorial:
Mozilla Firefox also works fine in my experience.
Mark
It looks like I never replied. Yes, on Mac these days I use it with Firefox
Many thanks, it works!
+1 Anas
Great to hear
Thank you very much!!!
A very useful post! It works 🙂
Thanks for the feedback, I am glad it helped!
Pingback: Python, Conda, WSL 2 Ubuntu Setup on Windows 10 | Bradley Sawler
The chrome.exe needs double quotes due to blank space in the path:
c.NotebookApp.browser = ‘”C:\Program Files\Google\Chrome\Application\chrome.exe” %s’
Thank you for that, nice catch!