How to install and work with PyPy
Try a faster and easier way to manage your Python dependencies. Use Python 3.9 by ActiveState and build your own runtime with the packages and dependencies you need. Get started for free by creating an account on the ActiveState Platform or logging in with your GitHub account.
PyPy (not to be confused with the Python Package Index, which is abbreviated PyPI) is an open source, alternative implementation of the Python programming language. PyPy is a just-in-time compiler that often runs faster than CPython.
Most Python code runs efficiently on PyPy except for:
- Code that depends on Python 3.7+ syntax.
- Code that depends on CPython extensions, which either does not work or performs poorly when run in PyPy.
Note that pip does not come with PyPy, but can be installed in a PyPy environment after PyPy has been installed.
PyPy is available for installation for Linux, MacOS, and Windows operating systems.
PyPy can be either compiled from source code and then installed, or it can be downloaded as a set of precompiled binary files that will let you run PyPy as-is. The latter approach is simplest and recommended:
Create a directory in which you would like to download and run PyPy from. In Windows, for example:
Download PyPy precompiled binary files in zipped format for your operating system from:
Once you have downloaded PyPy and unzipped it in your installation directory, it can either be run locally from within the directory or run globally once you set the PyPy environment variables. To open a PyPy shell, enter:
Setting PyPy Environment Variables
Once PyPy has been installed, you can set the environment PATH for PyPy, the same as you would for Python.
Set PyPy Environment PATH on Linux
You can make PyPy available system-wide by putting a symlink to the PyPy executable in /usr/local/bin. It is important to use a symlink and not move the binary, otherwise PyPy will not be able to find its library.
PyPy Environment PATH on MacOS
You can make PyPy available system-wide as a PATH environment variable by making an entry in the .bash_profile file. Note that the entry will need to be upper-case so that it will be recognized throughout the system, and words linked with underscores.
PyPy Environment PATH on Windows
To run PyPy from any location, you need to add the directory in which it is installed in, as a System PATH environment variable:
- Open the Control Panel and navigate to System.
- Click on Advanced system settings in the upper left panel.
- Click on Environment Variables.
- Under System Variables, scroll down then double-click the PATH variable.
- Click New, and add the directory where PyPy is installed, e.g.C:\PyPy
- Select OK.
Conda Install PyPy
PyPy can be installed in a Conda environment, with either of the following commands:
conda install -c conda-forge pypy conda install -c conda-forge/label/cf202003 pypy
PyPy Pip Installation
Pip/pip3 is the official package manager for Python, but it can also be used by PyPy for installing Python modules. The easiest way to install pip for PyPy on any operating system is to use the ensurepip package that comes with Python and PyPy by default.
To install ensurepip, run:
pypy -m ensurepip
To ensure you’re using the latest version of ensurepip, run:
pypy -m ensurepip --upgrade
Pip can now be installed by doing the following:
- Download the latest version of get-pip.py from https://bootstrap.pypa.io/.
- CD into the download directory, and enter the following command:
MacOS or Linux:
sudo pypy get-pip.py
Add pip to your System Path Environment Variables so you can run it from any location in your operating system (refer to the instructions for adding PyPy as a System PATH environment variable above).
PyPy Pip3 Upgrade
You can upgrade pip In a PyPy environment by running the following command:
pypy -m pip3 install --upgrade pip
PyPy Pip Usage
Pip can be sued in PyPy deployments to install packages and their required dependencies from the Python Package Index (PyPI), using the following command:
pypy -m pip install <package_name>
A modern solution to Python package management – Try ActiveState’s Platform
Dependency resolution is at the core of the ActiveState Platform. When you create a project and start adding requirements, the Platforms tell you what dependencies those requirements have.
The ActiveState Platform is a cloud-based build tool for Python. It provides build automation and vulnerability remediation for:
- Python language cores, including Python 2.7 and Python 3.5+
- Python packages and their dependencies, including:
- Transitive dependencies (ie., dependencies of dependencies)
- Linked C and Fortran libraries, so you can build data science packages
- Operating system-level dependencies for Windows, Linux, and macOS
- Shared dependencies (ie., OpenSSL)
- Find, fix and automatically rebuild a secure version of Python packages like Django and environments in minutes
The ActiveState Platform aims to handle every dependency for every language. That means handling libraries down to the C/C++ level, external tools, and all the conditional dependencies that exist. To take things even further, our ultimate goal is to support multi-language projects. That means that you can create a project using both Python and Perl packages, and we’ll make sure that both languages are using the same (up to date) OpenSSL version.
Python Dependency Management In Action
Get a hands-on appreciation for how the ActiveState Platform can help you manage your dependencies for Python environments. Just run the following command to install Python 3.9 and our package manager, the State Tool:
powershell -Command "& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://platform.activestate.com/dl/cli/install.ps1'))) -activate-default ActiveState-Labs/Python-3.9Beta"
sh <(curl -q https://platform.activestate.com/dl/cli/install.sh) --activate-default ActiveState-Labs/Python-3.9Beta
Now you can run state install <packagename>. Learn more about how to use the State Tool to manage your Python environment.
Let us know your experience in the ActiveState Community forum.