Skip to main content

Installing Z3 Python Bindings

The Z3 Python bindings provide a high-level interface to the Z3 theorem prover. This guide covers multiple installation methods.

Installation via pip

The easiest way to install Z3 is using pip:
This installs the z3-solver package, which includes:
  • Pre-built Z3 native libraries
  • Python bindings
  • Z3 executable
  • C/C++ header files
It’s recommended to use a virtual environment:

Verifying Installation

Test your installation:

Building from Source

For the latest development version or custom builds, compile from source.

Prerequisites

  • Python 3.7 or later
  • CMake 3.4 or later
  • C++ compiler with C++20 support:
    • GCC/Clang on Linux/macOS
    • Visual Studio 2019+ on Windows

Linux/macOS Build

Windows Build

Using Visual Studio Command Prompt:
Or using CMake:

Installing Python Package from Source

From the src/api/python directory:
For development mode (editable install):

Platform-Specific Notes

Linux

After building, you may need to update library paths:
Add to ~/.bashrc for persistence.

macOS

Set the dynamic library path:

Windows

Ensure the Z3 bin directory is in your PATH:

Package Requirements

The Z3 Python package has minimal dependencies:
  • Python: 3.7+
  • importlib-resources: For Python < 3.9 (installed automatically)
  • setuptools: For building from source (≥70)

Troubleshooting

Import Error: DLL/SO Not Found

If you get library loading errors: Linux:
macOS:
Windows: Add Z3’s bin directory to your system PATH.

Build Failures

Ensure you have:
  • CMake installed (pip install cmake if needed)
  • C++20 compatible compiler
  • Sufficient disk space (build artifacts are ~500MB)

Version Conflicts

If you have multiple Z3 installations:

Upgrading

To upgrade to the latest version:

Uninstalling

Remove Z3 from your Python environment:
If you built from source using make:

Next Steps