-
Notifications
You must be signed in to change notification settings - Fork 889
Open
Labels
Description
🐛 Bug Reports
I can not link to the correct virtual environment in OS X. Instead, the system Python is always used.
🌍 Environment
- Your operating system and version: OS X Big Sur 11.5
- Your python version: 3.8.11
- How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: Python was installed with homebrew via
brew install [email protected]A virtual environment was created withpython3 -m venv redvoxand is located at /Users/anthony/venvs/redvox - Your Rust version (
rustc --version): rustc 1.56.0-nightly (9c25eb7aa 2021-07-25) - Your PyO3 version: 14.1
- Have you tried using latest PyO3 main (replace
version = "0.x.y"withgit = "https://github.com/PyO3/pyo3")?:
No
💥 Reproducing
- Activate the virtual environment
source /Users/anthony/venvs/redvox/bin/activate - Ensure matplotlib is installed
pip install matplotlib - Run the rust code
cargo run
use pyo3::prelude::*;
use std::io::Result;
fn main() -> Result<()> {
let src = r#"
import sys
print(sys.executable, sys.path)
import matplotlib
"#;
Python::with_gil(|py| {
py.run(src, None, None).unwrap();
});
Ok(())
}The following shows how I activate the virtual environment and attempt to call the rust code. The error message I receive is also included.
anthony@REDVOX-00-MACBOOK-PRO rust-sandbox % source ~/venvs/redvox/bin/activate
(redvox) anthony@REDVOX-00-MACBOOK-PRO rust-sandbox % python3
Python 3.8.11 (default, Jun 29 2021, 03:08:07)
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> exit()
(redvox) anthony@REDVOX-00-MACBOOK-PRO rust-sandbox % cargo run
Compiling pyo3 v0.14.1
Compiling rust-sandbox v0.1.0 (/Users/anthony/Development/rust-sandbox)
Finished dev [unoptimized + debuginfo] target(s) in 4.63s
Running `target/debug/rust-sandbox`
/Users/anthony/Development/rust-sandbox/target/debug/rust-sandbox ['/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python38.zip', '/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8', '/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload', '/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'ModuleNotFoundError'>, value: ModuleNotFoundError("No module named 'matplotlib'"), traceback: Some(<traceback object at 0x100ddbbc0>) }', src/main.rs:12:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
I've tried setting PYTHONHOME and PYTHONPATH. Neither of these have worked for me. The system Python is always used no matter what I try. How can I get pyo3 to work with my virtual environment on OS X?
zommarin, AlexanderProd, mobile-bungalow, sportfloh and barakugav