Embedding a Python module in a Rust application #691
Unanswered
arctic-hen7
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there! First off, fantastic project, this is extremely useful!
I'm building a Rust desktop application with Tauri that needs to invoke a Python runtime, specifically to work with the
whisper
module (which has a lot of dependencies on PyTorch, etc.). I am a Rust programmer, and have rarely used Python, and I've been able to get everything working with dynamic linking, but I'm having some difficulties with static linking now. Having set up PyOxidizer withpyo3::with_embedded_python_interpreter
(I'm not usingpyembed
at the moment, for simplicity) running in a separate thread with a simplempsc
message-passing system set up, I now need to run a very, very simple Python file and call a function from it:(For those unfamiliar with
whisper
, this just takes an audio file and uses OpenAI's Whisper model to transcribe it to text.)This is the grand extent of the Python I need in my project, but it has caused a remarkable number of issues! I'm able to statically link everything by running
pyoxidizer generate-python-embedding-artifacts pyembedded
, and then I can usePYO3_CONFIG_FILE=$(pwd)/pyembedded/pyo3-build-config-file.txt PYTHONPATH=pyembedded/stdlib cargo tauri dev
to run the app (again, it's a desktop app using Tauri), which all works fine, except that the thread handling the Python runtime immediately fails, because thewhisper
module is not found.I'm afraid I'm finding the documentation quite difficult to follow, given my limited Python experience: is there an easy way I can import
whisper
into the Python environment that PyOxidizer statically links against? I don't have any explicit configuration set up for PyOxidizer, and I'm hesitant to generate anything, because the docs seem to imply that can't be done for a pre-existing project (but I may be wrong about this). Any guidance would be greatly appreciated!Beta Was this translation helpful? Give feedback.
All reactions