How to install Pypy (fast Python) and use it in VSC

What is PyPy?

First of all, Pypy is not the same as Pypi, which is the official third-party software repository. Pypy is an alternative implementation of the usual Python programming language, but with the advantage that it is way faster. For all the problems I have solved in different platforms and competitions, Pypy has given me better times (it did not happen in one specific problem, but it might be just a single internal bug... somehow).

Why Pypy?

There is no syntax difference between Python and Pypy, that is the beautiful of Pypy. You only need to be careful to code in the same version. If you code a program that runs in Python 2.7 with specific instructions that were valid only on 2.7 version, that program will only run in Pypy 2.7 and will give an error in any Pypy 3.#.

So, if you code a program in Python 3.7, Pypy 3.7 will run it as well, but way faster.

Here is an small comparison of their running times in a problem from Facebook Hacker Cup 2020.

Python vs Pypy.

Why not?

Like everything in life, something with some "pros" comes with some "cons". Pypy loses out on newer syntax in Python, so you will need to wait until the new features come down to Pypy. Also, with Pypy you won't have access to the "pip" command in the terminal, so you won't be able to download external libraries to use them. And finally, it is not well known, some platforms (Google cof cof) will have just Pypy2, and you will need to code with Python 2.7 syntax. Some people do not even know it exists. Imagine their surprise when they see their programs run up to 10 times faster.

Download and installation (Windows)

You need to go to the oficial page of Pypy and download the version you want.

It is Zip file, so you only need to extract the files in the directory you want to store your Pypy. I recommend to create the directory "C:/Pypy##" to have an easy access to the compiler.

Files of Pypy zip.

You might need the VC runtime library installer vcredist.x86.exe, check it out.

Environment Variable (Windows)

To write the environment variables, go to:
Control Panel > System and Security > System > Advanced system Settings > Environment Variables
Then, you will need to edit the variable "Path" in the 2 sections. Then, you will need to add the paths "C:\Pypy##\", in case you took my advice, otherwise search for your Pypy path, and add them to the "Path" variable.

Editing the environment variables.

The order of the variables affects the behavior in the terminal, the first python path will be set, and the following ones will be ignored. In case you have multiple versions of Pypy installed.

Pypy in the terminal

To run the Python files with Pypy, you only need to type "pypy# [python_path]".

Running Pypy in the terminal.

Pypy in VSC

Remember that if you use the same version (2.7, 3.6, or 3.7), there is no difference in the syntax between Python and Pypy.

If you want to run your codes with Pypy, you only need to change the compiler/interpreter. In the bottom-left of VSC there is the button to do that.

VSC bottom-left.

Then a small menu will show up in the middle of VSC, where you can select between the different Python versions you have already installed in your computer.

Python versions.

Then search for the Pypy version you have.

Pypy interpreter.