Cyberithub

How to Install PyPy on Linux Using 6 Easy Steps

Advertisements

In this article, I will take you through the steps to install PyPy on Linux using 6 Easy Steps. PyPy is as the alternative implementation of the Python programming language to CPython. It is built using the RPython language that was co-developed with it. It is known to be faster than CPython. PyPy implements Python 2.7.18, and 3.7.10. It supports almost all the Python Standard library modules. It is extensively tested for use in Linux machines. But it also works fine on both Windows and Mac machines.

Main Features

  • It comes with Just-in-time compiler which is really really fast.
  • Memory intensive python programs would end up using less memory than the CPython.
  • It has support for both Stackless and greenlets.
  • It is highly compatible with existing Python code which means it supports almost all the popular libraries.

How to Install PyPy on Linux Using 6 Easy Steps

How to Install PyPy on Linux Using 6 Easy Steps

Also Read: Solved: ModuleNotFoundError: No module named 'sklearn' in Python3

Step 1: Prerequisites

a) You should have a running Linux Server.

b) You should have sudo or root access to run privileged commands.

c) You should have access to Internet to download and install the package.

 

Step 2: Update Your Server

In the first step you need to update your System cache with all the latest package versions available from all enabled repositories. Depending on the Linux distributions you are using, run below update step.

a) On Ubuntu/Debian System

If you are using Ubuntu/Debian based systems, then you need to use sudo apt update command to sync the package cache with all the latest available versions.

cyberithub@ubuntu:~$ sudo apt update
[sudo] password for cyberithub:
Hit:1 https://download.docker.com/linux/ubuntu focal InRelease
Hit:2 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:3 http://ppa.launchpad.net/ubuntu-toolchain-r/test/ubuntu focal InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Hit:7 https://apt.boltops.com stable InRelease
Get:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Fetched 336 kB in 2s (173 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done

b) On RHEL/CentOS System

If you are using RHEL/CentOS based systems, then you need to use sudo yum update to install the latest updates.

[cyberithub@localhost ~]$ sudo yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.nxtgen.com
* epel: mirror.samayservices.com
* extras: mirrors.nxtgen.com
* updates: mirrors.nxtgen.com
Resolving Dependencies
--> Running transaction check
---> Package glibc.x86_64 0:2.17-325.el7_9 will be updated
---> Package glibc.x86_64 0:2.17-326.el7_9 will be an update
---> Package glibc-common.x86_64 0:2.17-325.el7_9 will be updated
---> Package glibc-common.x86_64 0:2.17-326.el7_9 will be an update
---> Package glibc-devel.x86_64 0:2.17-325.el7_9 will be updated
---> Package glibc-devel.x86_64 0:2.17-326.el7_9 will be an update
---> Package glibc-headers.x86_64 0:2.17-325.el7_9 will be updated
---> Package glibc-headers.x86_64 0:2.17-326.el7_9 will be an update
---> Package golang.x86_64 0:1.16.13-2.el7 will be updated
.....................................

 

Step 3: Install PyPy

You can choose any of the below method to install PyPy Python interpreter depending on the Linux distribution you are using and the tool set available in your System.

a) Using snap

If you have snap utility available in your System then you can installed PyPy as snap package using sudo snap install pypy --classic command as shown below.

cyberithub@ubuntu:~$ sudo snap install pypy --classic
pypy 7.3.9 from The PyPy Project (pypyproject) installed

b) Using apt

If you are using Debian/Ubuntu based systems then you need to use sudo apt install pypy command to install the package as shown below. This will download and install the package along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt install pypy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
pypy-lib
Suggested packages:
pypy-doc pypy-tk
The following NEW packages will be installed:
pypy pypy-lib
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 13.6 MB of archives.
After this operation, 87.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 pypy-lib amd64 7.3.1+dfsg-2 [2,442 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 pypy amd64 7.3.1+dfsg-2 [11.2 MB]
Fetched 13.6 MB in 5s (2,967 kB/s)
Selecting previously unselected package pypy-lib:amd64.
(Reading database ... 257752 files and directories currently installed.)
Preparing to unpack .../pypy-lib_7.3.1+dfsg-2_amd64.deb ...
..................................................

c) Using yum 

If you are having RHEL/CentOS based systems, then you need to use sudo yum install pypy command to install the package as shown below.

[cyberithub@localhost ~]$ sudo yum install pypy
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 9.1 kB 00:00:00
* base: mirrors.nxtgen.com
* epel: mirror.samayservices.com
* extras: mirrors.nxtgen.com
* updates: mirrors.nxtgen.com
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/5): epel/x86_64/group_gz | 96 kB 00:00:00
(2/5): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/5): extras/7/x86_64/primary_db | 250 kB 00:00:00
(4/5): epel/x86_64/primary_db | 7.0 MB 00:00:02
(5/5): updates/7/x86_64/primary_db | 17 MB 00:00:10
Resolving Dependencies
--> Running transaction check
---> Package pypy.x86_64 0:5.0.1-3.el7 will be installed
--> Processing Dependency: pypy-libs(x86-64) = 5.0.1-3.el7 for package: pypy-5.0.1-3.el7.x86_64
--> Processing Dependency: libpypy-c.so()(64bit) for package: pypy-5.0.1-3.el7.x86_64
--> Running transaction check
---> Package pypy-libs.x86_64 0:5.0.1-3.el7 will be installed
...................................................

d) Using Prebuilt Binary

You can go to official website and download the latest release by using wget https://downloads.python.org/pypy/pypy3.9-v7.3.9-linux64.tar.bz2 command from terminal as shown below.

cyberithub@ubuntu:~$ wget https://downloads.python.org/pypy/pypy3.9-v7.3.9-linux64.tar.bz2
--2022-09-21 01:17:51-- https://downloads.python.org/pypy/pypy3.9-v7.3.9-linux64.tar.bz2
Resolving downloads.python.org (downloads.python.org)... 199.232.104.175, 2a04:4e42:5a::175
Connecting to downloads.python.org (downloads.python.org)|199.232.104.175|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32841328 (31M) [application/x-tar]
Saving to: ‘pypy3.9-v7.3.9-linux64.tar.bz2’

pypy3.9-v7.3.9-linux64.tar.bz2 100%[============================================================================>] 31.32M 6.86MB/s in 4.6s

2022-09-21 01:17:56 (6.85 MB/s) - ‘pypy3.9-v7.3.9-linux64.tar.bz2’ saved [32841328/32841328]

You can extract the downloaded package by using tar -xvf pypy3.9-v7.3.9-linux64.tar.bz2 command as shown below.

cyberithub@ubuntu:~$ tar -xvf pypy3.9-v7.3.9-linux64.tar.bz2
.........................................
pypy3.9-v7.3.9-linux64/include/pypy3.9/setobject.h
pypy3.9-v7.3.9-linux64/include/pypy3.9/compile.h
pypy3.9-v7.3.9-linux64/include/pypy3.9/pyerrors.h
pypy3.9-v7.3.9-linux64/include/pypy3.9/cpyext_memoryobject.h
pypy3.9-v7.3.9-linux64/include/pypy3.9/pysignals.h
pypy3.9-v7.3.9-linux64/bin/
pypy3.9-v7.3.9-linux64/bin/python3.9
pypy3.9-v7.3.9-linux64/bin/libpypy3.9-c.so.debug
pypy3.9-v7.3.9-linux64/bin/libpypy3.9-c.so
pypy3.9-v7.3.9-linux64/bin/python
pypy3.9-v7.3.9-linux64/bin/python3
pypy3.9-v7.3.9-linux64/bin/pypy3
pypy3.9-v7.3.9-linux64/bin/pypy3.9
pypy3.9-v7.3.9-linux64/bin/pypy
pypy3.9-v7.3.9-linux64/bin/pypy3.9.debug

Once extracted, you can directly run the prebuilt binary by using ./pypy3.9-v7.3.9-linux64/bin/pypy3 as shown below.

cyberithub@ubuntu:~$ ./pypy3.9-v7.3.9-linux64/bin/pypy3
Python 3.9.12 (05fbe3aa5b0845e6c37239768aa455451aa5faba, Mar 29 2022, 08:15:34)
[PyPy 7.3.9 with GCC 10.2.1 20210130 (Red Hat 10.2.1-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>>

 

Step 4: Check Version

After successful installation, you can verify the installed version by using pypy --version command as shown below.

cyberithub@ubuntu:~$ pypy --version
Python 2.7.13 (7.3.1+dfsg-2, Apr 21 2020, 05:05:41)
[PyPy 7.3.1 with GCC 9.3.0]

 

Step 5: Using PyPy

It is now time to test the Python Interpreter by running pypy command on the Linux terminal. You can write a simple print statement to display "Hello World" on the output as shown below.

cyberithub@ubuntu:~$ pypy
Python 2.7.13 (7.3.1+dfsg-2, Apr 21 2020, 05:05:41)
[PyPy 7.3.1 with GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> print("Hello World")
Hello World
>>>>

 

Step 6: Uninstall PyPy

Although I won't recommend but in case you are done with PyPy and looking to uninstall the Interpreter from your system then you need to choose one of the below method to uninstall depending on how you have installed the package in your System.

a) Using Snap

If you have installed as a snap package then to uninstall you need to run sudo snap remove pypy command as shown below.

cyberithub@ubuntu:~$ sudo snap remove pypy
pypy removed

b) Using apt

If you have installed the package using apt package manager then you can uninstall it by using sudo apt remove pypy command as shown below.

NOTE:

Please be very sure before running below command in a Production System. Any unwanted package removal can cause critical damage to your Server and may result in heavy production loss.
cyberithub@ubuntu:~$ sudo apt remove pypy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
pypy-lib
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
pypy
0 upgraded, 0 newly installed, 1 to remove and 10 not upgraded.
After this operation, 72.1 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 259164 files and directories currently installed.)
Removing pypy (7.3.1+dfsg-2) ...
Processing triggers for man-db (2.9.1-1) ...

c) Using yum

If you have installed the Python Interpreter by using yum utility then you can uninstall PyPy package by using sudo yum remove pypy command as shown below.

[cyberithub@centos ~]$ sudo yum remove pypy
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package pypy.x86_64 0:5.0.1-3.el7 will be erased
--> Processing Dependency: /usr/bin/pypy for package: pypy-libs-5.0.1-3.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package pypy-libs.x86_64 0:5.0.1-3.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Removing:
pypy x86_64 5.0.1-3.el7 @epel 18 k
Removing for dependencies:
pypy-libs x86_64 5.0.1-3.el7 @epel 97 M

Transaction Summary
=============================================================================================================================================================
Remove 1 Package (+1 Dependent package)

Installed size: 97 M
Is this ok [y/N]: y
......................................

Leave a Comment