Skip to content

Commit fee0acc

Browse files
committed
fix venv search
1 parent 3bab68b commit fee0acc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tauri-plugin-python"
3-
version = "0.3.2"
3+
version = "0.3.3"
44
authors = [ "Marco Mengelkoch" ]
55
description = "A tauri 2 plugin to use python code in the backend."
66
keywords = ["rust", "python", "tauri", "gui"]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tauri-plugin-python-api",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"author": "Marco Mengelkoch",
55
"description": "Javascript package for tauri 2 python plugin.",
66
"type": "module",

src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
8181

8282
fn init_python(code: String, dir: PathBuf) {
8383
let mut sys_pyth_dir = format!("sys.path.append('{}')", dir.to_str().unwrap());
84-
let venv_dir = dir.join(".venv");
84+
let venv_dir = dir.join(".venv").join("lib");
8585
if Path::exists(venv_dir.as_path()) {
86-
sys_pyth_dir += "\n";
87-
sys_pyth_dir += &format!("sys.path.append('{}')", venv_dir.to_str().unwrap());
86+
if let Ok(py_dir) = venv_dir.read_dir() {
87+
for entry in py_dir.flatten() {
88+
let site_packages = entry.path().join("site-packages");
89+
if Path::exists(site_packages.as_path()) { // use first site-packages found, ignoring version
90+
sys_pyth_dir += "\n";
91+
sys_pyth_dir += &format!("sys.path.append('{}')", site_packages.to_str().unwrap());
92+
break;
93+
}
94+
}
95+
}
8896
}
8997
let path_import_and_code = format!(
9098
r#"

0 commit comments

Comments
 (0)