-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PYO3_PYTHON
and LD_LIBRARY_PATH
pointing to venv
are ignored
#4841
Comments
PYO3_PYTHON
and LD_LIBRARY_PATH
does not change the interpreter PYO3_PYTHON
and LD_LIBRARY_PATH
pointing to venv
are ignored
Hi,
Regarding
My workaround is to run |
@Hennzau thanks for your reply. That's indeed a typo, I edited it to avoid confusion. However the issue persists, I've set up a simple reproduction repository. See the README for steps to install and run it. Exporting I also tried to call a shell in the My expectation would be that I could point PyO3 to a virtualenv and that it should then activate and use that virtualenv. |
Hi, the easiest solution is to always activate your venv before running Once pyo3 is compiled you cannot change anything from your If you don't want to activate your venv: I tried something with the
and pass it while running
It should build successfully but then when i run it, I get:
|
hmm 🤔 I was under the impression that the python binary was linked at runtime, not during compilation..? Clearly I don't really understand how it works. The docs state the following:
reference: https://pyo3.rs/main/building-and-distribution Reading that it seems that configuring The use case I have is that I want to write a rust server application (with tokio) and then have that server application invoke functions in a python library. Having to activate the While calling a python library from Rust may seem overly complicated, I was hoping to be able to do some machine learning in my python lib (using |
Alright, turns out this isn't a bug at all 🫣 please feel free to close this ticket. PYO3 seems to do exactly what can be expected of it, the issue was due to my lack of understanding of the python interpreter and virtual environments. However, the pyo3 documentation referenced above was not really helpful in clarifying what was required to configure pyo3 to use a specific virutal env at runtime. That could be a potential enhancement. The documentaiton mentions By modifying the |
Bug Description
I would like pyo3 to use the
.venv
I've created in my python library, when calling functions from that library from rust. - but it ignores the values configured in my environment.From what I've read I understood it as
PYO3_PYTHON
and/orLD_LIBRARY_PATH
can be used to configure the path to the python interpreter executable. I exported them in the shell and then ran my rust project like soping
is just a function I use to test the setup. In the rust app, theping
function is invoked through a clap command. The handler looks like so:Steps to Reproduce
Reproduction repository:
https://github.com/jakob-lilliemarck/pyo3-python-env-ignored
Backtrace
Your operating system and version
Linux 6.6.65-1-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Dec 11 22:24:04 UTC 2024 x86_64 GNU/Linux
Your Python version (
python --version
)3.12.7 (main, Oct 1 2024, 11:15:50) [GCC 14.2.1 20240910]
Your Rust version (
rustc --version
)rustc 1.85.0-nightly (a224f3807 2024-12-09)
Your PyO3 version
0.23.3
How did you install python? Did you use a virtualenv?
Can't recall, but from the looks of it I installed the global one using
brew
, then I created a virtual env in my project bypython -m venv .venv
Additional Info
No response
The text was updated successfully, but these errors were encountered: