LinuxCommandLibrary

pypy

Run Python code with PyPy interpreter

TLDR

Start a REPL (interactive shell)

$ pypy
copy

Execute script in a given Python file
$ pypy [path/to/file.py]
copy

Execute script as part of an interactive shell
$ pypy -i [path/to/file.py]
copy

Execute a Python expression
$ pypy -c "[expression]"
copy

Run library module as a script (terminates option list)
$ pypy -m [module] [arguments]
copy

Install a package using pip
$ pypy -m pip install [package]
copy

Interactively debug a Python script
$ pypy -m pdb [path/to/file.py]
copy

SYNOPSIS

pypy [ options ] [ -c command | scriptfile | - ] [ arguments ]

PARAMETERS

-c command
    Execute the Python code specified as a string.

scriptfile
    Execute the Python code contained in the specified script file.

-
    Read Python code from standard input.

[arguments]
    Arguments passed to the Python script (available in `sys.argv`).

-v
    Print verbose messages.

-O
    Optimize generated bytecode slightly.

-OO
    Remove doc-strings in addition to the -O optimizations.

-W arg
    Warning control; arg is action:message:category:module:lineno.

-E
    Ignore PYTHON* environment variables (such as PYTHONPATH).

-h
    Display help message.

DESCRIPTION

The `pypy` command is the interpreter for the PyPy implementation of the Python programming language. PyPy is an alternative Python interpreter that focuses on speed and efficiency through the use of Just-in-Time (JIT) compilation.

Unlike the standard CPython interpreter, PyPy translates Python code into an intermediate representation, which is then analyzed and optimized at runtime by its JIT compiler. This can lead to significant performance improvements, especially for long-running or computationally intensive tasks.

Using `pypy` is generally straightforward; you invoke it with a Python script file as an argument, similar to how you would use `python` with CPython. Because PyPy's JIT compiler needs a 'warm-up' period to observe code behavior and start optimizations, the first few executions might not show immediate speedups. The command generally aims for better memory management and performance than CPython in many real-world scenarios, but it's important to test your code with both interpreters to evaluate performance in your specific case. PyPy aims for high compatibility with standard Python, supporting a wide range of Python features and libraries.

CAVEATS

PyPy's JIT compiler requires a warm-up period before significant performance gains are realized. Short-running scripts may not benefit as much. Also, C extensions might require adaptation for PyPy, and some libraries might have compatibility issues. Performance gains will vary substantially depending on the nature of your code. Initial startup time can also be a bit longer as well. Not all Python versions are supported, so make sure that the version of Python you need is supported by a PyPy release.

COMPATIBILITY

PyPy aims for high compatibility with standard Python. Most pure-Python libraries and frameworks should work with PyPy. However, C extensions may require modifications or replacements, and some libraries may not be fully compatible. Check the PyPy documentation for specific compatibility notes.

INSTALLATION

PyPy can be installed using package managers like `apt`, `yum`, or `brew`, or by downloading a pre-built binary from the official PyPy website.

HISTORY

PyPy's development started in the early 2000s as a research project focused on implementing a Python interpreter using the RPython language, a statically-typed subset of Python. The primary goal was to create a flexible and extensible interpreter that could be more easily optimized than CPython.

The Just-in-Time (JIT) compilation capabilities were a key innovation, allowing PyPy to significantly outperform CPython in many benchmarks, particularly those involving loops and numerical computations. Over the years, PyPy has gained traction within the Python community, especially for applications where performance is critical. It is often used for tasks like scientific computing, data analysis, and web development.

SEE ALSO

python(1), python3(1)

Copied to clipboard