PyPy

PyPy is an alternate implementation of the Python 2.7, 3.7, 3.8 and 3.9 (beta) interpreters. PyPy's benefits are in the area of speed, memory usage, sandboxing and stacklessness. It is compatible with CPython with some exceptions. PyPy also can be used to compile RPython programs to C code.

Installation

For Python 2.7, install the pypy package. For Python 3, install the pypy3 package.

PyPy is installed in /opt/pypy/ or /opt/pypy3 and the main pypy executable is bin/pypy-c.

Usage

Basic PyPy usage is done through the pypy or pypy3 command and functions similarly to CPython usage. Enter

$ pypy -h

to view the listing of pypy options.

Interactive interpreter

To load the PyPy interactive interpreter, run

$ pypy

Run program from file

To run a Python program from a file in PyPy, run

$ pypy example.py

Virtual environment creation

To make a virtual environment with PyPy:

$ virtualenv --python=/usr/bin/pypy venv-pypy

See Python/Virtual environment for further information.

Installing pip

As Python packages for PyPy are not distributed as Arch packages, it is most convenient to install what you require as your own user:

$ pypy -m ensurepip --user
$ pypy -m pip install --user --upgrade pip

Once you have pip, you can install any package you need, e.g., sqlalchemy:

$ pypy -m pip install --user sqlalchemy

If you would prefer to install packages system-wide, just run the previous commands as root without the --user. Note that this will result in the packages being installed in /opt/pypy without the package manager being aware of them.

EasyInstall

Python libraries and programs can be installed in PyPy through EasyInstall.

EasyInstall installation

EasyInstall does not come with the PyPy package but is automatically installed when installing pip and located at /opt/pypy/bin/easy_install.

Installing EasyInstall packages

To install the EasyInstall package into PyPy, enter

# /opt/pypy/bin/easy_install package_name

Packages will be located at . Installed libraries and applications will be at . Programs installed through EasyInstall on PyPy can usually be ran with where program_name is the name of the PyPy program.

EasyInstall package example

The following will install the Lamson email framework:

# /opt/pypy/bin/easy_install lamson

The following will run the framework's gen -project command:

$ /opt/pypy/bin/lamson gen -project testproject
gollark: Anyway, point is that if any language is allowed, people have to be able to know *all* the ones in use to participate to some degree.
gollark: You are wrong, bismuth you.
gollark: No, I mean to judge who wrote some code, it's important to have a decent working knowledge of that language, right?
gollark: There's also an important meta-level point about how when people *complained* about palaiologos's choice, they did not decide to actually discuss the merits of it with the community and have a productive discussion but just insist they were right and run a nonsensical vote.
gollark: Python is very simple and most people can sort of write it ish.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.