How to call python dynamic shared library from rust using pyo3?

I have a python shared library that is condensed by python codes(python3 -m Cython.Build.Cythonize -3b *.py;rm *.c;rm -rf build;), if i want to use it in python, i can simply import and use it, how can i do so in rust?

Have you read pyo3's user guide on how to call python from rust? Calling Python from Rust - PyO3 user guide. Does it answer your question? If not, what exactly have you tried and what error did you get? Could you share your code with us?

Hi I met the problem that inside the pyo3, I do not know how to link the dynamic libraries, all these are done by python itself, so I met error could not import xxx.

So basically you are doing this: Calling Python from Rust - PyO3 user guide, and it fails with an error that you can't import the cython library?

1 Like

Are the modules in PYTHONPATH or just in the current working directory? Generally, if the modules can be imported by python they can be imported by pyo3 because it simply calls pythons import under the hood.

yes I can't import cython library and I searched but it seems no one is using in this way.

it's in current working dir.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.