Setup Python Environment for LBCNet
setup_lbcnet.RdThis function configures the Python environment for LBCNet, ensuring the correct Python version and dependencies are loaded. It prioritizes virtual environments (`venv`) over Conda unless explicitly requested. Additionally, users can explicitly choose to use the system Python.
Usage
setup_lbcnet(
use_conda = FALSE,
envname = "r-lbcnet",
use_system_python = FALSE,
create_if_missing = FALSE,
system_python_path = NULL
)Arguments
- use_conda
Logical. If `TRUE`, it attempts to use Conda (`r-lbcnet`) instead of virtualenv. Default is `FALSE`, meaning virtualenv/system Python is preferred.
- envname
A character string specifying the name of the virtual environment or Conda environment to use. Default is `"r-lbcnet"`. One can use `virtualenv_list()` or `conda_list()` to check the available Python environments in your system.
- use_system_python
Logical. If `TRUE`, the function will force the use of the system Python (`Sys.which("python")`) instead of a virtual environment or Conda. Default is `FALSE`. If both `use_system_python = TRUE` and `use_conda = TRUE`, the function will prioritize system Python.
- create_if_missing
Logical. If `TRUE`, the function creates the specified virtual environment (`envname`) if it does not exist. Default is `FALSE`, meaning it will only warn if `envname` is missing and list available environments. This applies only when `use_conda = FALSE`, as Conda environments must be created manually.
- system_python_path
A character string specifying the full path to a system Python executable. If provided and `use_system_python = TRUE`, it overrides `Sys.which("python")`. Default is `NULL`.
Details
The function automatically detects the best available Python environment.
If a user specifies `envname`, it tries to activate that environment.
If both `use_system_python = TRUE` and `use_conda = TRUE`, the function will prioritize system Python.
It ensures required Python packages (`torch`, `numpy`, `pandas`, `tqdm`) are available using `py_require()`.
It is recommended to set up the `reticulate` package properly before running `setup_lbcnet()`.
If encountering errors like `"not a Python virtualenv"`, it is advised to delete and recreate the virtual environment.
If multiple Python versions exist on the system, ensure that packages are installed in the correct Python environment.
Use `reticulate::py_config()` to verify the active Python environment before running the function.
Examples
if (FALSE) { # \dontrun{
setup_lbcnet() # Automatically configures the best available Python environment
setup_lbcnet(envname = "r-lbcnet") # Uses a specific virtual environment (warns if missing)
setup_lbcnet(envname = "r-lbcnet", create_if_missing = TRUE) # Creates "r-lbcnet" if missing
setup_lbcnet(use_conda = TRUE) # Forces Conda if available
setup_lbcnet(use_system_python = TRUE) # Forces to use system Python
setup_lbcnet(use_system_python = TRUE, use_conda = TRUE) # Prioritizes system Python over Conda
} # }