Conda Environment#

Because this project calls both Python and R tools from Jupyter, the recommended setup is a single conda/mamba environment.

Create Environment#

From the project root:

mamba env create -f environment.yml
conda activate sctk
python -m ipykernel install --user --name sctk --display-name "Python (sctk)"

If you do not use mamba:

conda env create -f environment.yml
conda activate sctk
python -m ipykernel install --user --name sctk --display-name "Python (sctk)"

Then choose Python (sctk) in Jupyter.

Update Environment#

After editing environment.yml:

mamba env update -f environment.yml --prune

or:

conda env update -f environment.yml --prune

Do not use pip install -r requirements-dev.txt to update runtime packages inside this environment. Runtime packages are owned by conda, except for the small explicit pip: block in environment.yml. In particular, ipykernel=6.25.2 is intentionally installed and pinned by conda.

If an environment already contains conda and pip copies of the same package, create a fresh environment from environment.yml, validate it, switch the Jupyter kernel, and only then remove the old environment.

Why Conda First#

environment.yml installs Python, R, rpy2, and Bioconductor packages into the same environment. That is less fragile than mixing a pip Python environment with a separate system R installation.

requirements.txt remains only as a pip fallback.

Quick Check#

python -c "import sctk, rpy2.robjects as ro; print(sctk.__version__); print(ro.r('R.version.string')[0])"
python -c "from sctk.r import require_r_package; require_r_package('scDblFinder'); print('scDblFinder ok')"
python -c "from sctk.r import require_r_package; require_r_package('SoupX'); print('SoupX ok')"
python -c "import ipykernel; assert ipykernel.__version__ == '6.25.2'"

In restricted environments, run validation commands with writable cache directories:

mamba run -n sctk env NUMBA_CACHE_DIR=/tmp/sctk_numba_cache MPLCONFIGDIR=/tmp/sctk_mpl_config XDG_CACHE_HOME=/tmp/sctk_xdg_cache python -c "import sctk, scanpy, decoupler, rpy2"