Skip to content

Commit 2219cb0

Browse files
committed
auto load venv
1 parent 820f92a commit 2219cb0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use py_lib_pyo3 as py_lib;
2626

2727
pub use error::{Error, Result};
2828
use models::*;
29-
use std::path::PathBuf;
29+
use std::path::{Path, PathBuf};
3030

3131
#[cfg(desktop)]
3232
use desktop::Python;
@@ -80,14 +80,19 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
8080
}
8181

8282
fn init_python(code: String, dir: PathBuf) {
83+
let mut sys_pyth_dir = format!("sys.path.append('{}')", dir.to_str().unwrap());
84+
let venv_dir = dir.join(".venv");
85+
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());
88+
}
8389
let path_import_and_code = format!(
8490
r#"
8591
import sys
86-
sys.path.append('{}')
92+
{}
8793
{}
8894
"#,
89-
dir.to_str().unwrap(),
90-
code
95+
sys_pyth_dir, code
9196
);
9297
py_lib::run_python(StringRequest {
9398
value: path_import_and_code,

0 commit comments

Comments
 (0)