Specify the python interpreter at runtime #3079
-
Hi ! I'm writing a rust binary that uses pyo3 to compile python files, and inspect their bytecode. I have a strict restriction to use python3.8. Reading the doc of pyo3, I ended up creating a Now, it happens that sometimes the binary is run with a PATH where I found another question around specifying the libpythonXXX.so statically, so my understanding might be flowed. At the end of the day, I'm looking to statically specify which Python (exe or so) will be used by pyo3. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I am not sure if this is helpful, but the interpreter specified at build time via I think the easier way to achieve what you want would be to set |
Beta Was this translation helpful? Give feedback.
I am not sure if this is helpful, but the interpreter specified at build time via
PYO3_PYTHON
is used only to determine the Python configuration, e.g. linker flags, and its path is not used at runtime. Based on this, we should dynamically linklibpython3.8.so
if you specified a CPython 3.8 binary at build time. Linking against an absolute path like/usr/lib/libpython3.8.so
to ensure that nothing else on the dynamic loader's search paths is picked up, would require that we selectively overwrite the linker flags determined by invoked the Python interpreter which does not seem very practical.I think the easier way to achieve what you want would be to set
LD_LIBRARY_PATH
at runtime to point …