If the create_cissvae_env() helper function fails or you
prefer to set up your environment manually, you can create a Python
virtual environment using either R (via reticulate) or the command
line.
Before starting, ensure you have:
reticulate package installedYou can check your Python version by running the following from your terminal:
# Find Python installations on your system
reticulate::py_discover_config()
# Or check for a specific version
reticulate::virtualenv_starter("3.10")If no suitable Python version is found, you can install Python directly through reticulate:
# Install Python 3.10 (recommended)
reticulate::install_python(version = "3.10")
# Or install Python 3.11
reticulate::install_python(version = "3.11")
# Check available versions after installation
reticulate::py_versions()
# Verify the installation worked
reticulate::virtualenv_starter("3.10")Note: reticulate::install_python()
will:
If the installation fails or you prefer more control, you can also install Python manually:
brew install python@3.10) or download from python.orgsudo apt install python3.10 on Ubuntu)After manual installation, restart R and rerun
reticulate::py_discover_config() to verify reticulate can
find the new Python installation.
Once you’ve identified the python installation you want to use, you
can use the reticulate package to create your virtual environment either
in the default location (~/.virtualenvs/) or in a directory
of your choice.
# Create virtual environment in default location (~/.virtualenvs/)
reticulate::virtualenv_create(
envname = "cissvae_env",
python = NULL, # Use system default Python
packages = c("pip", "setuptools", "wheel")
)
# Alternative: Create in a specific directory
reticulate::virtualenv_create(
envname = "./my_venvs/cissvae_env", # Relative path
python = "/usr/bin/python3.10", # Specific Python version
packages = c("pip", "setuptools", "wheel")
)In order to use your virtual environment, you have to tell reticulate to activate and use it with the command below. You will repeat this command in each new R session that you want to use the virtual environment in.
Before using the virtual environment for the first time, install the
necessary dependencies and the ciss-vae python package to
the environment. This only needs to be done once per environment (unless
you want to update the packages later).
# Install core dependencies first
reticulate::virtualenv_install(
envname = "cissvae_env",
packages = c(
"numpy",
"pandas",
"torch",
"scikit-learn",
"optuna",
"rich",
"matplotlib",
"leiden-alg",
"python-igraph"
)
)
# Install CISS-VAE from PyPI
reticulate::virtualenv_install(
envname = "cissvae_env",
packages = "ciss-vae"
)After installing the packages, you can use the following commands to make sure the ciss_vae package installed correctly.
# Check if CISS-VAE installed correctly
reticulate::py_run_string("import ciss_vae; print('CISS-VAE version:', ciss_vae.__version__)")
# List all installed packages
reticulate::virtualenv_install(envname = "cissvae_env", packages = character(0))Please note, python must be installed for this to work.
On Windows:
On Windows OS, the command to activate the environment differs based on the terminal you are using.
# Command Prompt
cissvae_env\Scripts\activate
# PowerShell
cissvae_env\Scripts\Activate.ps1
# Git Bash
source cissvae_env/Scripts/activateOn macOS/Linux:
You should see (cissvae_env) at the beginning of your
prompt when activated.
After creating the environment via command line, tell R where to find it:
library(reticulate)
# Point to your manually created environment
reticulate::use_virtualenv("/path/to/your/project/cissvae_env", required = TRUE)
# On Windows, the path might look like:
# reticulate::use_virtualenv("C:/Users/YourName/project/cissvae_env", required = TRUE)
# Verify connection
reticulate::py_config()If you prefer conda over venv:
# Create conda environment from R
reticulate::conda_create(
envname = "cissvae_env",
python_version = "3.10",
packages = c("numpy", "pandas", "matplotlib", "scikit-learn")
)
# Activate and install additional packages
reticulate::use_condaenv("cissvae_env", required = TRUE)
reticulate::conda_install("cissvae_env", c("torch", "optuna", "rich", "hdbscan", "ciss-vae"))Solution: Ensure Python is in your system PATH, or specify the full path:
Solution:
Solution: Install packages one by one to identify the problematic package:
Solution: Verify the environment is properly activated:
Solution: Always activate your environment at the start of each R session: