forked from ricolab/Chromatinsight
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup_python_env.R
More file actions
30 lines (22 loc) · 894 Bytes
/
setup_python_env.R
File metadata and controls
30 lines (22 loc) · 894 Bytes
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
# 1. Install reticulate if not already installed
if (!requireNamespace("reticulate", quietly = TRUE)) {
install.packages("reticulate")
}
# Load reticulate
library(reticulate)
# 2. Ensure pip is installed in the system
system("python -m ensurepip --default-pip")
# 3. Ensure pandas is installed globally (outside virtualenv)
system("python -m pip install --upgrade pip pandas")
# 4. Create the virtual environment if it doesn't exist
if (!dir.exists("~/mi_env")) {
system("python -m venv ~/mi_env")
}
# 5. Use the virtual environment
reticulate::use_virtualenv("~/mi_env", required = TRUE)
# 6. Install Python packages in the virtual environment
reticulate::py_install(c("pandas", "scikit-learn"))
# 7. Check Python configuration
reticulate::py_config()
# 8. Test if the libraries are correctly installed
reticulate::py_run_string("import pandas; import sklearn; print('Success!')")