{"id":4225,"library":"pythran","title":"Pythran","description":"Pythran is an Ahead-of-Time (AOT) compiler that translates a subset of Python, primarily focused on scientific computing and numerical kernels, into native C++14 modules. It aims to provide C++/Fortran-like performance for Python code, leveraging multi-cores and SIMD instructions. The current stable version is 0.18.1, and it actively maintains a release cadence of several updates per year, supporting Python 3.7 and upward.","status":"active","version":"0.18.1","language":"en","source_language":"en","source_url":"https://github.com/serge-sans-paille/pythran","tags":["compiler","performance","numeric","scientific-computing","ahead-of-time-compilation","numpy","c++"],"install":[{"cmd":"pip install pythran","lang":"bash","label":"Install Pythran"}],"dependencies":[{"reason":"Lex & Yacc parsing, required for Pythran's AST processing.","package":"ply","optional":false},{"reason":"Used for building and distributing Pythran extensions, especially via PythranExtension.","package":"setuptools","optional":false},{"reason":"Python AST that abstracts the underlying Python version, used in AST transformations.","package":"gast","optional":false},{"reason":"Core dependency for numerical operations and array support.","package":"numpy","optional":false},{"reason":"Extracts semantic information about static Python code, used in Pythran's analysis passes.","package":"beniget","optional":false},{"reason":"C++ library dependency, often vendored in PyPI packages but may be external for other distributions.","package":"boost","optional":true},{"reason":"C++ library for SIMD vectorization, often vendored in PyPI packages.","package":"xsimd","optional":true},{"reason":"Required to compile the generated C++ code.","package":"C++14 enabled compiler (e.g., g++>=5, clang>=3.5)","optional":false}],"imports":[{"note":"Pythran compiles a Python file (e.g., `my_module.py`) into a native shared library (e.g., `my_module.so` or `my_module.pyd`) which can then be imported directly as a standard Python module.","symbol":"compiled_module","correct":"import compiled_module"},{"note":"For IPython/Jupyter integration, load the magic function to compile code directly in cells using `%%pythran`.","symbol":"pythran.magic","correct":"%load_ext pythran.magic"}],"quickstart":{"code":"# dprod.py\n\"\"\" Naive dotproduct! Pythran supports numpy.dot \"\"\"\n#pythran export dprod(int list, int list)\ndef dprod(l0, l1):\n    \"\"\"WoW, generator expression, zip and sum.\"\"\"\n    return sum(x * y for x, y in zip(l0, l1))\n\n# To compile the Python file to a native module:\n# pythran dprod.py\n\n# Then, import and use the compiled module:\n# python -c 'import dprod; print(dprod.dprod([1,2,3], [4,5,6]))'","lang":"python","description":"Create a Python file with numerical kernels annotated for export. Compile it using the `pythran` command-line tool, then import the resulting native module. This example defines a dot product function."},"warnings":[{"fix":"Ensure your project uses Python 3.7 or newer.","message":"Pythran dropped support for Python 2.7 after version 0.9.5. It now exclusively supports Python 3.7 and upward.","severity":"breaking","affected_versions":"<=0.9.5 (Python 2.7 support), >0.9.5 (Python 3.7+ only)"},{"fix":"Design your functions to adhere to Pythran's supported Python subset, typically pure numerical functions operating on primitive types and NumPy arrays.","message":"Pythran only supports a subset of the Python language, specifically targeting numerical computing. Features like classes, polymorphic variables (with some exceptions), and heterogeneous containers (except tuples) are not supported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Update your system's C++ compiler to a version that supports C++14 standards.","message":"A C++14 enabled compiler (e.g., g++ >= 5, clang >= 3.5) is a prerequisite for Pythran. Older compilers may lead to compilation errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult Pythran's documentation for recommended optimization flags and consider setting them in `~/.pythranrc` or passing them directly to the `pythran` command.","message":"For optimal performance, users often need to explicitly specify compiler optimization flags (e.g., `-O3`, `-fopenmp`, `-march=native`) either via the `pythran` CLI or in a `~/.pythranrc` configuration file.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate build systems away from `numpy.distutils` if targeting Python 3.9+ with Pythran 0.18.0+.","message":"Support for `numpy.distutils` with Python 3.9 was obsoleted in Pythran 0.18.0. Users integrating Pythran into larger build systems might need to adapt.","severity":"deprecated","affected_versions":"0.18.0 and later"},{"fix":"Refer to the Pythran documentation for detailed Windows installation and configuration instructions, especially regarding compiler setup.","message":"Windows support for Pythran is ongoing and primarily targets Visual Studio 2017 or clang-cl. Specific environment variables (`CXX`, `CC`) might be required for proper setup.","severity":"gotcha","affected_versions":"All versions on Windows"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}