You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Architecture.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,20 +34,21 @@ To summarize, there are six main parts to the PyO3 codebase.
34
34
35
35
[`pyo3-ffi`] contains wrappers of the [Python/C API]. This is currently done by hand rather than
36
36
automated tooling because:
37
-
- it gives us best control about how to adapt C conventions to Rust, and
38
-
- there are many Python interpreter versions we support in a single set of files.
37
+
38
+
- it gives us best control about how to adapt C conventions to Rust, and
39
+
- there are many Python interpreter versions we support in a single set of files.
39
40
40
41
We aim to provide straight-forward Rust wrappers resembling the file structure of [`cpython/Include`](https://github.com/python/cpython/tree/main/Include).
41
42
42
43
We are continuously updating the module to match the latest CPython version which PyO3 supports (i.e. as of time of writing Python 3.13). The tracking issue is [#1289](https://github.com/PyO3/pyo3/issues/1289), and contribution is welcome.
43
44
44
45
In the [`pyo3-ffi`] crate, there is lots of conditional compilation such as `#[cfg(Py_LIMITED_API)]`,
45
-
`#[cfg(Py_3_7)]`, and `#[cfg(PyPy)]`.
46
+
`#[cfg(Py_3_8)]`, and `#[cfg(PyPy)]`.
46
47
`Py_LIMITED_API` corresponds to `#define Py_LIMITED_API` macro in Python/C API.
47
48
With `Py_LIMITED_API`, we can build a Python-version-agnostic binary called an
Copy file name to clipboardExpand all lines: guide/src/building-and-distribution.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
This chapter of the guide goes into detail on how to build and distribute projects using PyO3.
4
4
The way to achieve this is very different depending on whether the project is a Python module implemented in Rust, or a Rust binary embedding Python.
5
-
For both types of project there are also common problems such as the Python version to build for and the [linker](https://en.wikipedia.org/wiki/Linker_(computing)) arguments to use.
5
+
For both types of project there are also common problems such as the Python version to build for and the [linker](<https://en.wikipedia.org/wiki/Linker_(computing)>) arguments to use.
6
6
7
7
The material in this chapter is intended for users who have already read the PyO3 [README](./index.md).
8
8
It covers in turn the choices that can be made for Python modules and for Rust binaries.
@@ -19,7 +19,7 @@ By default it will attempt to use the following in order:
19
19
- The `python` executable (if it's a Python 3 interpreter).
20
20
- The `python3` executable.
21
21
22
-
You can override the Python interpreter by setting the `PYO3_PYTHON` environment variable, e.g. `PYO3_PYTHON=python3.7`, `PYO3_PYTHON=/usr/bin/python3.9`, or even a PyPy interpreter `PYO3_PYTHON=pypy3`.
22
+
You can override the Python interpreter by setting the `PYO3_PYTHON` environment variable, e.g. `PYO3_PYTHON=python3.8`, `PYO3_PYTHON=/usr/bin/python3.9`, or even a PyPy interpreter `PYO3_PYTHON=pypy3`.
23
23
24
24
Once the Python interpreter is located, `pyo3-build-config` executes it to query the information in the `sysconfig` module which is needed to configure the rest of the compilation.
25
25
@@ -109,7 +109,7 @@ You can then open a Python shell in the output directory and you'll be able to r
109
109
110
110
If you're packaging your library for redistribution, you should indicate the Python interpreter your library is compiled for by including the [platform tag](#platform-tags) in its name.
111
111
This prevents incompatible interpreters from trying to import your library.
112
-
If you're compiling for PyPy you *must* include the platform tag, or PyPy will ignore the module.
112
+
If you're compiling for PyPy you _must_ include the platform tag, or PyPy will ignore the module.
113
113
114
114
#### Bazel builds
115
115
@@ -245,18 +245,18 @@ There are three steps involved in making use of `abi3` when building Python pack
245
245
246
246
#### Minimum Python version for `abi3`
247
247
248
-
Because a single `abi3` wheel can be used with many different Python versions, PyO3 has feature flags `abi3-py37`, `abi3-py38`, `abi3-py39` etc. to set the minimum required Python version for your `abi3` wheel.
249
-
For example, if you set the `abi3-py37` feature, your extension wheel can be used on all Python 3 versions from Python 3.7 and up.
250
-
`maturin` and `setuptools-rust` will give the wheel a name like `my-extension-1.0-cp37-abi3-manylinux2020_x86_64.whl`.
248
+
Because a single `abi3` wheel can be used with many different Python versions, PyO3 has feature flags `abi3-py38`, `abi3-py39`, `abi3-py310` etc. to set the minimum required Python version for your `abi3` wheel.
249
+
For example, if you set the `abi3-py38` feature, your extension wheel can be used on all Python 3 versions from Python 3.8 and up.
250
+
`maturin` and `setuptools-rust` will give the wheel a name like `my-extension-1.0-cp38-abi3-manylinux2020_x86_64.whl`.
251
251
252
252
As your extension module may be run with multiple different Python versions you may occasionally find you need to check the Python version at runtime to customize behavior.
253
253
See [the relevant section of this guide](./building-and-distribution/multiple-python-versions.md#checking-the-python-version-at-runtime) on supporting multiple Python versions at runtime.
254
254
255
255
PyO3 is only able to link your extension module to abi3 version up to and including your host Python version.
256
-
E.g., if you set `abi3-py38` and try to compile the crate with a host of Python 3.7, the build will fail.
256
+
E.g., if you set `abi3-py39` and try to compile the crate with a host of Python 3.8, the build will fail.
257
257
258
258
> [!NOTE]
259
-
> If you set more that one of these `abi3` version feature flags the lowest version always wins. For example, with both `abi3-py37` and `abi3-py38` set, PyO3 would build a wheel which supports Python 3.7 and up.
259
+
> If you set more that one of these `abi3` version feature flags the lowest version always wins. For example, with both `abi3-py38` and `abi3-py39` set, PyO3 would build a wheel which supports Python 3.8 and up.
260
260
261
261
#### Building `abi3` extensions without a Python interpreter
262
262
@@ -321,17 +321,17 @@ The known complications are:
321
321
- To import compiled extension modules (such as other Rust extension modules, or those written in C), your binary must have the correct linker flags set during compilation to export the original contents of `libpython.a` so that extensions can use them (e.g. `-Wl,--export-dynamic`).
322
322
- The C compiler and flags which were used to create `libpython.a` must be compatible with your Rust compiler and flags, else you will experience compilation failures.
323
323
324
-
Significantly different compiler versions may see errors like this:
324
+
Significantly different compiler versions may see errors like this:
325
325
326
-
```text
327
-
lto1: fatal error: bytecode stream in file 'rust-numpy/target/release/deps/libpyo3-6a7fb2ed970dbf26.rlib' generated with LTO version 6.0 instead of the expected 6.2
328
-
```
326
+
```text
327
+
lto1: fatal error: bytecode stream in file 'rust-numpy/target/release/deps/libpyo3-6a7fb2ed970dbf26.rlib' generated with LTO version 6.0 instead of the expected 6.2
328
+
```
329
329
330
-
Mismatching flags may lead to errors like this:
330
+
Mismatching flags may lead to errors like this:
331
331
332
-
```text
333
-
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libpython3.9.a(zlibmodule.o): relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIE
334
-
```
332
+
```text
333
+
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libpython3.9.a(zlibmodule.o): relocation R_X86_64_32 against `.data' can not be used when making a PIE object; recompile with -fPIE
334
+
```
335
335
336
336
If you encounter these or other complications when linking the interpreter statically, discuss them on [issue 416 on PyO3's GitHub](https://github.com/PyO3/pyo3/issues/416).
337
337
It is hoped that eventually that discussion will contain enough information and solutions that PyO3 can offer first-class support for static embedding.
0 commit comments