{"id":530,"library":"llvmlite","title":"llvmlite","description":"llvmlite is a lightweight Python binding to LLVM, primarily used for just-in-time (JIT) compilation. It allows Python code to construct LLVM Intermediate Representation (IR) in pure Python, which is then passed to LLVM for compilation and optimization. Maintained by the Numba team, it releases several times a year, often in conjunction with Numba updates and LLVM version bumps. The current stable version is 0.46.0.","status":"active","version":"0.46.0","language":"python","source_language":"en","source_url":"https://github.com/numba/llvmlite","tags":["llvm","jit","compiler","numba","ir"],"install":[{"cmd":"pip install llvmlite","lang":"bash","label":"PyPI"},{"cmd":"conda install llvmlite","lang":"bash","label":"Anaconda"}],"dependencies":[{"reason":"Requires Python 3.10 or newer (Python 3.9 support dropped in 0.44.0).","package":"python","optional":false},{"reason":"llvmlite packages from Numba maintainers statically link LLVM. However, if building from source or using dynamically-linked packages (e.g., from conda-forge), a compatible LLVM installation (including development files and C++ compiler/CMake) is required. llvmlite 0.45.0+ requires LLVM 20.x.x.","package":"LLVM","optional":true}],"imports":[{"note":"Used for building LLVM Intermediate Representation (IR) in pure Python.","symbol":"ir","correct":"from llvmlite import ir"},{"note":"Used for interacting with the LLVM runtime, including parsing IR, creating execution engines, and JIT compilation.","symbol":"binding","correct":"import llvmlite.binding as llvm"}],"quickstart":{"code":"from ctypes import CFUNCTYPE, c_double\nfrom llvmlite import ir\nimport llvmlite.binding as llvm\n\n# All these initializations are required for JIT compilation\nllvm.initialize_native_target()\nllvm.initialize_native_asmprinter()\n\n# Define the LLVM IR for a simple function (double fpadd(double a, double b) { return a + b; })\ndouble = ir.DoubleType()\nfnty = ir.FunctionType(double, (double, double))\n\nmodule = ir.Module(name=__file__)\nfunc = ir.Function(module, fnty, name=\"fpadd\")\n\nblock = func.append_basic_block(name=\"entry\")\nbuilder = ir.IRBuilder(block)\na, b = func.args\nresult = builder.fadd(a, b, name=\"res\")\nbuilder.ret(result)\n\n# Convert textual LLVM IR into in-memory representation\nllvm_module = llvm.parse_assembly(str(module))\nllvm_module.verify()\n\n# Create an ExecutionEngine suitable for JIT code generation\ntarget = llvm.Target.from_default_triple()\ntarget_machine = target.create_target_machine()\nengine = llvm.create_mcjit_compiler(llvm_module, target_machine)\n\n# Finalize the engine to make the function available\nengine.finalize_object()\nengine.run_static_constructors()\n\n# Look up the function pointer and cast it to a C function\nfunc_ptr = engine.get_function_address(\"fpadd\")\ncfunc = CFUNCTYPE(c_double, c_double, c_double)(func_ptr)\n\n# Run the function\nres = cfunc(1.0, 2.5)\nprint(f\"Result of fpadd(1.0, 2.5): {res}\") # Expected: 3.5","lang":"python","description":"This example demonstrates how to define a simple floating-point addition function using `llvmlite.ir`, compile it using `llvmlite.binding`, and execute it via `ctypes`. It covers IR construction, module parsing, execution engine setup, and function invocation."},"warnings":[{"fix":"Remove any calls to `llvm.binding.initialize()` from your code.","message":"The `llvm.binding.initialize()` function, previously used to initialize LLVM, is deprecated and removed. In `llvmlite` 0.45.x, it raises a `RuntimeError`, and in 0.46.x it is completely removed. LLVM core initialization is now automatic.","severity":"breaking","affected_versions":">=0.45.0"},{"fix":"Migrate code to use Opaque Pointers. Refer to the llvmlite documentation's migration guide for specifics on updating existing code.","message":"Support for Typed Pointers in the binding layer was removed in `llvmlite` 0.45.0. Future versions (>=0.46, specifically >=0.47) will make Opaque Pointers the default for the IR layer and eventually remove Typed Pointer support entirely, aligning with LLVM 17+. Code relying on Typed Pointers will break if not migrated.","severity":"breaking","affected_versions":">=0.45.0"},{"fix":"Ensure your LLVM installation (if explicitly managed) matches the version required by your `llvmlite` installation. Using pre-built binaries (pip wheels or conda packages) often avoids this issue as they bundle compatible LLVM versions.","message":"Each `llvmlite` version is specifically targeted and compatible with particular LLVM feature versions. Using a mismatched LLVM version (e.g., when building from source or with dynamic linking) can lead to build failures or runtime issues. Consult the `llvmlite` documentation for the compatibility matrix. For example, `llvmlite` 0.45.0+ requires LLVM 20.x.x.","severity":"gotcha","affected_versions":"*"},{"fix":"Prefer `pip install llvmlite` or `conda install llvmlite` for most use cases to leverage pre-compiled binaries.","message":"Building `llvmlite` from source is a complex process requiring specific development tools (C++ compiler, CMake, LLVM development libraries). It is generally recommended to install pre-built binaries via `pip` or `conda` unless you have specific reasons to build from source.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade your Python environment to Python 3.10 or newer.","message":"Official support for Python 3.9 was dropped with `llvmlite` 0.44.0. The minimum supported Python version is now 3.10.","severity":"deprecated","affected_versions":">=0.44.0"}],"env_vars":null,"last_verified":"2026-05-12T14:41:51.968Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Ensure that LLVM development packages are installed and `llvm-config` is in your system's PATH. If using `pip`, try `pip install llvmlite` and if it fails, consider using `conda install llvmlite` as it typically provides pre-built binaries that include a compatible LLVM. If building from source, set the `LLVM_CONFIG` environment variable to the full path of your `llvm-config` executable (e.g., `export LLVM_CONFIG=/usr/local/opt/llvm/bin/llvm-config`).","cause":"This error occurs during `llvmlite` installation (especially when building from source) because the `llvm-config` executable, which is used to locate LLVM libraries and headers, cannot be found in the system's PATH or at the location specified by the `LLVM_CONFIG` environment variable. This often happens on systems without a proper LLVM development installation or when `pip` attempts to build `llvmlite` from a source distribution due to an unsupported Python version or architecture.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'llvm-config'"},{"fix":"Update `llvmlite` to the version specified or a compatible one with your `Numba` installation, usually by running `pip install --upgrade llvmlite` or `conda update llvmlite`. It's often best to let `conda` manage both, e.g., `conda install numba llvmlite`.","cause":"This error arises when the installed versions of `Numba` and `llvmlite` are incompatible. `Numba` has a strict dependency on specific `llvmlite` versions, and if `llvmlite` is older than required, this error is raised.","error":"ImportError: Numba requires at least version X.Y.Z of llvmlite. Installed version is A.B.C. Please update llvmlite."},{"fix":"Install the required LLVM version (e.g., via your system's package manager, Homebrew, or by compiling from source) and then set the `LLVM_CONFIG` environment variable to the absolute path of the `llvm-config` executable for that LLVM installation before attempting to install `llvmlite` again. For example: `export LLVM_CONFIG=/path/to/llvm-X.Y/bin/llvm-config` followed by `pip install llvmlite`.","cause":"This indicates that `llvmlite` could not find a suitable LLVM installation (specifically version X.Y or newer) during its build process. It explicitly suggests setting the `LLVM_CONFIG` environment variable to point to the correct `llvm-config` executable.","error":"RuntimeError: Building llvmlite requires LLVM X.Y+ Be sure to set LLVM_CONFIG to the right executable path."},{"fix":"Reinstall `llvmlite` using a reliable method, preferably `conda install llvmlite` to leverage pre-built, statically linked packages. If using `pip` and encountering issues, ensure you have the necessary build tools (like `cmake`, `g++`, Visual Studio on Windows) and a compatible LLVM installation (as referenced by `LLVM_CONFIG`) for your system and Python version.","cause":"This error occurs when `llvmlite`'s Python bindings (specifically `llvmlite.binding`) cannot find or load the underlying shared library (`libllvmlite.so`, `.dll`, or `.dylib`). This often points to a failed or incomplete build of `llvmlite` itself, or an incompatibility with the system's LLVM libraries if `llvmlite` was not statically linked or linked against a mismatched LLVM version.","error":"OSError: Could not find/load shared object file"},{"fix":"Install `llvmlite` using `pip install llvmlite` or `conda install llvmlite`. Ensure you are installing it into the correct Python environment that you are currently using. If it was already installed, verify the environment or check your `PYTHONPATH`.","cause":"This error means that the Python interpreter cannot find the `llvmlite` package. This typically happens if `llvmlite` was not successfully installed, was installed in a different Python environment, or the current environment's `PYTHONPATH` does not include the installation directory.","error":"ModuleNotFoundError: No module named 'llvmlite'"}],"ecosystem":"pypi","meta_description":null,"install_score":50,"install_tag":"draft","quickstart_score":33,"quickstart_tag":"draft","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"draft","tag_description":"notable install failures or slow imports","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.1,"disk_size":"180M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"182M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"174M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.9,"disk_size":"173M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":1,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.8,"disk_size":"147M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"draft","tag_description":"notable failures across runtimes","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}