How to run PyPy as your VS Code Jupyter interpreter

Maurice Henry Buettgenbach
Level Up Coding
Published in
5 min readJul 10, 2021

--

Ever wondered how you can run PyPy as an interpreter for your Jupyter notebooks in Visual Studio Code? Well, I have. And it took me forever to make it work.

I don’t know how that’s going for you but I spend more time setting up my environment and installing the required libraries than I spend actually coding.

Since I wasn’t able to find a comprehensive guide on how to set up PyPy for my VS Code on my windows system, I decided to share my findings and (maybe) make your life a little easier.

What do you need?

  • Visual Studio Code 2021
  • Visual Studio Code Python extension
  • Visual Studio 2019
  • PyPy 3.7

Step 1: Install Visual Studio Code

If you don’t have VS code yet, now is the time to download it! You can download the desired version here.

After the download launches the execution file, follow the installation guide. The installation should not require any admin rights. Afterward launch VSCode and the home screen will pop up.

VSCode home screen. Image by author.

Step 2: Get the Python extension

VS Code offers a ready to use Python extension that enables you to work with Jupyter notebooks within VS Code. To install the extension, open your VSCode and open the extensions tab by pressing Ctrl + Shift + X. In the search bar type in “Python”, select the Python extension by Microsoft and install it.

Python extension pack by Microsoft. Image by author.

To start a new Python project, press Ctrl + Shift + P to open the command line in VSCode and type “Python: Create New Blank Jupyter Notebook”. Press enter and VSCode will open a new Jupyter Notebook for you:

Jupyter Notebook in VSCode. Image by author.

Step 3: Install PyPy

Next, we need to download PyPy 3.7 and install it in our desired path. You can download PyPy here. Once you have downloaded the ZIP folder, unpack it your desired path.

Theoretically, you are now ready to execute PyPy on your system. However, it is highly recommendable that you first add the path to your PyPy execution file to your windows system. To do so, follow the next steps:

Open the system control panel by pressing your windows key and typing “Control Panel”. Then click on “System”.

Control Panel. Image by author.

Next, click on “Advanced system settings” and provide your administrator details.

System Panel. Image by author.

A new window will open. Here, select “Environment variables”.

Advanced system settings. Image by author.

Then click on “Path” and “New”. You then can add the path to the folder with your pypy3.exe and give the environment variable a respective name.

Environment variables. Image by author.

Step 4: Ensure pip

Alright! Since we now have successfully installed PyPy, we need to make sure that we can install the required libraries via the pip command. To do so, we need to open the windows command console and enter the following command:

pypy -m ensurepip

Sometimes the above command does not work as it can be necessary to provide the full path to your pypy3.exe. In this case, add the full path to your pypy3.exe and repeat the command:

PATH -m ensurepip

In my case this looks like this:

C:\Users\MauriceHenry\Documents\PyPy\pypy3.7-v7.3.5-win64\pypy3.exe -m ensurepip

Step 5: Install Visual Studio 2019

Perfect! Theoretically, we would be ready to select PyPy as our interpreter in our VS Code Jupyter by now. However, PyPy requires us to install the Ipython kernel again . However, the installation will throw a nasty little error as the installer cannot find a file with the name “vcvarsall.bat”.

The file is part of the “Desktop Development With C++ Workload” package that can be installed via Visual Studio 2019. To do so, install Visual Studio 2019 from this page.

Once downloaded, run the installer, select the following packages and hit start. Depending on your specs, this step will take some time so I recommend to have a quick coffee break at this point.

Workload section in Visual Studio 2019. Image by author.

Step 6: Select PyPy as your interpreter

If you want to switch between different interpreters in VS Code, press Ctrl + Shift + P to open the command line and type “Python: Select interpreter”. VSCode will show you the currently active interpreter and other options. To add a new interpreter, select “Enter interpreter path…” and simply copy the path to your pypy3.exe file and hit enter.

Interpreter selection in VS Code. Image by author.

Step 7: Install the Ipython kernel for PyPy

Before we are ready to start coding with PyPy as our interpreter, we still need to install the Ipython kernel. Luckily, the Python extension by Microsoft will help you to do so.

Simply type a code snippet of your choice in the first Jupyter cell and execute it. VS Code will then open a pop-up window, asking you whether you want to install the Ipython kernel. Once you pressed “Install”, you can lean back and watch VS Code install the kernel for you.

Cabin Fever Reaction GIF. Image by Gliphy.

Voilà! You will see that your code has executed after the installation. You are now ready to use PyPy as an interpreter within your VS Code Jupyter notebook.

--

--