-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_python.rs
More file actions
50 lines (44 loc) · 1.44 KB
/
Copy pathsetup_python.rs
File metadata and controls
50 lines (44 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::process::Command;
use std::env;
use which::which;
fn main() {
// Check if Python is installed
if let Ok(python_exe) = which("python3") {
println!("Found Python 3 executable at: {:?}", python_exe);
// Check for a virtual environment
if env::var("VIRTUAL_ENV").is_err() {
println!("No virtual environment found. Creating one...");
Command::new("python3")
.arg("-m")
.arg("venv")
.arg("venv")
.status()
.expect("Failed to create a virtual environment.");
}
// Activate the virtual environment
env::set_var("VIRTUAL_ENV", "venv");
// Install Python dependencies
install_python_dependencies();
} else {
eprintln!("Python 3 executable not found. Please ensure Python 3 is installed and in your PATH.");
std::process::exit(1);
}
}
fn install_python_dependencies() {
let status = Command::new("pip")
.arg("install")
.arg("torch")
.arg("torchvision")
.arg("torchaudio")
.arg("requests")
.arg("transformers")
.arg("Pillow")
.status()
.expect("Failed to install Python dependencies.");
if status.success() {
println!("Python dependencies installed successfully.");
} else {
eprintln!("Failed to install Python dependencies.");
std::process::exit(1);
}
}