Work with Jupyter Notebooks in VS Code without installing Anaconda

Faraz Naeem Piracha
4 min readJun 15, 2024

--

A laptop screen with code written in Python language
Photo by Chris Ried on Unsplash

Introduction:

If you’re here, it means that you most probably know about Jupyter and Anaconda, which ships Jupyter within its ecosystem.

Recently my Anaconda environment broke due to my tinkering with some configuration files. I was unable to start Jupyter and thus complete my work.

This article will tell you how you can work with Jupyter Notebooks even if you don’t have Anaconda and Jupyter installed in your environment.

Prerequisites:

You need to have VS Code (a no-brainer 💀) installed on your system beforehand. Installing VS Code is straightforward, so I will not elaborate on it here.

Step 1: Set up extensions

After VS Code is installed, it is time to proceed to the next step. Now, you need to install some extensions:

1. Python, published by Microsoft

  • The first extension is aptly-named ‘Python’. I have it already installed and enabled in this image.
  • Installing this extension also installs two more extensions: ‘Python Debugger’ and ‘Pylance’.

2. Jupyter Extension Pack, published by Microsoft

  • Install the ‘Jupyter Extension Pack’, also provided by Microsoft. This extension contains 4 extensions.
  • After successful installation it will look something like this:

Step 2: Create or open a Jupyter Notebook

After installing this extension you can open an existing Jupyter Notebook from your storage or create a new Jupyter Notebook by selecting Create: New Jupyter Notebook from the command palette (Ctrl + Shift + P).

Step 3: Set up kernel

Now you have to select a kernel that will run the code cells in this file. Click on the ‘Select Kernel’ option as shown in the image below:

This displays the 2 types of sources for the kernel environment:

  1. Python Environments
  2. Existing Jupyter Server

If you have a working Jupyter Server, you can select the second option and select the appropriate server. We will use the ‘Python Environments’ option here.

Selecting it displays all the available (and detected) Python environments. Virtual and conda environments are also displayed here, if present. Since my environment only had the default Python 3.12 installation, no other environment is shown here.

Select ‘Create Python Environment’, do not select the global Python install as your environment. Explore this link to understand why you should use venv.

Now we are presented with 2 options of creating a ‘Venv’ or ‘Conda’ environment. We will proceed with the ‘Venv’ option.

Next, we are prompted to select an interpreter for our virtual environment creation. Select the interpreter from the default Python installation as shown below:

VS Code will start the installation of the virtual environment, and complete it in a few moments.

Step 4: ipykernel Installation

A notification showing the location of the loaded environment will be shown. Additionally you can see the selected environment on the top-right corner of the notebook.

Now after all this process, if the virtual environment does not have ‘ipykernel’, VS Code will either prompt you immediately or after you try to run some code, to install ‘ipykernel’, as shown below:

Click on ‘Install’ and let VS Code handle the rest.

Step 5: Run code!

Now you are able to run the code present in the Notebook and work with it easily.

Conclusion:

Congratulations! You can now easily work with your Jupyter Notebooks in VS Code, which I personally prefer over the default Jupyter. This change allows you to enjoy your custom VS Code environment while getting your work done.

Thank you for reading until the end. Before you go, please consider clapping 👏 and following me to stay informed about new articles I publish.

--

--

Faraz Naeem Piracha
0 Followers

Hi! I am a Software Engineer, and I'm trying to document everyday problems I encounter during work, 1 step at a time. My GitHub is: github.com/farazokc/