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: README.md
+60-13Lines changed: 60 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,10 @@ This [tauri](https://v2.tauri.app/) v2 plugin is supposed to make it easy to use
4
4
It uses [RustPython](https://github.com/RustPython/RustPython) or alternatively [PyO3](https://pyo3.rs) as interpreter to call python from rust.
5
5
6
6
RustPython doesn't require python to be installed on the target platform and makes it
7
-
therefore easy to deploy your production binary. Unfortunately, it has some
8
-
compatibility issues and is slower than PyO3/CPython. PyO3 is also supported as optional Cargo feature for desktop applications.
9
-
PyO3 uses CPython as interpreter and therefore has a wide compatibility for available python libraries.
7
+
therefore easy to deploy your production binary. Unfortunately, it doesn't even support
8
+
some usually built-int python libraries and is slower than PyO3/CPython.
9
+
PyO3 is supported as optional Cargo feature for desktop applications.
10
+
PyO3 uses the usual CPython as interpreter and therefore has a wide compatibility for available python libraries.
10
11
It isn't used as default as it requires to make libpython available for the target platform,
11
12
which can be complicated, especially for mobile targets.
12
13
@@ -33,18 +34,39 @@ Android and iOS might also be able to run with PyO3 in theory but would require
33
34
to be compiled for the target platform. I still need to figure out how to
34
35
cross compile python and PyO3 for iOS and Android. Ping me if you know how to do that.
35
36
36
-
You can use this plugin for fast prototypes or for production code.
37
+
You can use this plugin for fast prototypes or for (early) production code.
37
38
It might be possible that you want to use some python library or code that
38
39
is not available for rust yet.
39
40
In case that you want to ship production software packages, you need
40
41
to make sure to also ship all your python code. If you use PyO3, you also need to ship libpython too.
41
42
42
43
### Switch from RustPython to PyO3
43
-
44
+
Using [PyO3](https://github.com/PyO3/pyo3) will support much more python libraries than RustPython as it is using CPython.
44
45
```toml
45
46
# src-tauri/Cargo.toml
46
47
tauri-plugin-python = { version="0.3", features = ["pyo3"] }
47
48
```
49
+
Unfortunately, using PyO3 will use a shared libpython by default, which makes
50
+
local development easy but makes
51
+
deployment of releases more complicated.
52
+
Therefore, it may be recommended to either use [pyoxidizer](https://github.com/indygreg/PyOxidizer) to embed libpython statically
53
+
or try to ship the dynamic libpython together with your application, for example as part
54
+
of the .venv. Check out the [PyO3 documentation](https://pyo3.rs/v0.24.2/building-and-distribution.html) for additional support.
55
+
56
+
Example of how to embed libpython statically using PyOxidizer:
57
+
58
+
This has just been tested locally on MacOS. It may be possible that this is more complicated and requires additional steps on your environment.
59
+
60
+
Install pyoxidizer `pip install pyoxidizer` in a venv and run it on bash:
PYO3_CONFIG_FILE = { value = "target/pyembed/pyo3-build-config-file.txt", relative = true }
68
+
```
69
+
You can check if the release binary has some shared libpython references by running `otool -L tauri_app` on MacOs or `ldd tauri_app` on linux.
48
70
49
71
## Example app
50
72
@@ -63,7 +85,7 @@ _tauri_plugin_functions = ["greet_python"] # make "greet_python" callable from
63
85
defgreet_python(rust_var):
64
86
returnstr(rust_var) +" from python"
65
87
```
66
-
- add `"bundle": {"resources": [ "src-python/**/*"],` to `tauri.conf.json` so that python files are bundled with your application
88
+
- add `"bundle": {"resources": [ "src-python/"],` to `tauri.conf.json` so that python files are bundled with your application
67
89
- add the plugin in your js, so
68
90
- add `import { callFunction } from 'tauri-plugin-python-api'`
69
91
- add `outputEl.textContent = await callFunction("greet_python", [value])` to get the output of the python function `greet_python` with parameter of js variable `value`
0 commit comments