Trouble with scvi environment from reticulate in R to run seurat pipeline

Hi,

I am on a MacOS Ventura, M2 Max

, I have installed conda in the terminal by:

brew install --cask mambaforge

curl -L -O “httpgithub(dot)com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh” bash Miniforge3-MacOSX-arm64.sh

Said yes to everything.

conda create -n scvi-env python=3.10

conda activate scvi-env

Got a
“/Users/mainuser/miniforge3/envs/scvi-env/”

conda install -c conda-forge r-base r-essentials r-reticulate

Then followed the Integration Seurat5 vignette Integrative analysis in Seurat v5 • Seurat

Loaded these packages…

library(Seurat)
library(SeuratData)
library(SeuratWrappers)
library(Azimuth)
library(ggplot2)
library(patchwork)
library(reticulate)
library(SeuratDisk)
library(harmony)
library(ggplot2)
library(patchwork)
options(future.globals.maxSize = 1e9)

Then just copypasted the code in (Integrative analysis in Seurat v5 • Seurat) until this error occurred.

obj ← IntegrateLayers(
object = obj, method = scVIIntegration,
new.reduction = “integrated.scvi”,
conda_env = “/Users/mainuser/miniforge3/envs/scvi-env/”, verbose = FALSE
)

This error was initially with Scanpy, but then after re-installing Scanpy. scvi has now become the ModuleNotFound error. And I can’t seem to perform scVIIntegration.

If I restart the session, restart my terminal. Rerun the code

conda create -n scvi-env python=3.10

conda activate scvi-en

conda install -c conda-forge r-base r-essentials r-reticulate

No problem encountered.

And re-run the code in R. Now I face the ModuleNotFound original error with scvi.

Then I restarted everything. Tried again and ran

pip3 install scvi-tools

pip3 install “scvi-tools[tutorials]”

The scvi and scanpy module errors have then been replaced by this.

File “/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py”, line 117, in _hook
return find_and_load(name, import)
File “/Users/sai/miniforge3/envs/scvi-env/lib/python3.10/site-packages/chex/_src/restrict_backends.py”, line 36, in
from jax._src import compiler
File “/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py”, line 119, in _find_and_load_hook
return _run_hook(name, _hook)
File “/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py”, line 93, in _run_hook
module = hook()
File “/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/reticulate/python/rpytools/loader.py”, line 117, in _hook
return find_and_load(name, import)
File “/Users/sai/miniforge3/envs/scvi-env/lib/python3.10/site-packages/jax/_src/compiler.py”, line 40, in
_DISABLE_MOST_OPTIMIZATIONS = config.DEFINE_bool(
AttributeError: module ‘jax._src.config’ has no attribute ‘DEFINE_bool’

── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

  1. └─Seurat::IntegrateLayers(…)
  2. └─SeuratWrappers (local) method(…)
  3. └─reticulate::import("scvi", convert = FALSE)
    
  4.   └─reticulate:::py_module_import(module, convert = convert)
    

Which leads me to believe I am doing something wrong with setting up the scvi-env and/or installation.

However, I don’t know how to further proceed.

Thank you, and best,

sessionInfo()
R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.0

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: America/Toronto
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] harmony_1.2.0 Rcpp_1.0.12 SeuratDisk_0.0.0.9021 reticulate_1.35.0 patchwork_1.2.0
[6] ggplot2_3.4.4 Azimuth_0.5.0 shinyBS_0.61.1 SeuratWrappers_0.3.19 pbmcsca.SeuratData_3.0.0
[11] pbmcref.SeuratData_1.0.0 pbmc3k.SeuratData_3.1.4 ifnb.SeuratData_3.0.0 SeuratData_0.2.2.9001 Seurat_5.0.1
[16] SeuratObject_5.0.1 sp_2.1-3
loaded via a namespace (and not attached):
[1] fs_1.6.3 ProtGenerics_1.34.0 matrixStats_1.2.0 spatstat.sparse_3.0-3
[5] bitops_1.0-7 DirichletMultinomial_1.44.0 TFBSTools_1.40.0 httr_1.4.7
[9] RColorBrewer_1.1-3 tools_4.3.2 sctransform_0.4.1 utf8_1.2.4
[13] R6_2.5.1 DT_0.31 lazyeval_0.2.2 uwot_0.1.16
[17] rhdf5filters_1.14.1 withr_3.0.0 prettyunits_1.2.0 gridExtra_2.3
[21] progressr_0.14.0 cli_3.6.2 Biobase_2.62.0 spatstat.explore_3.2-6
[25] fastDummies_1.7.3 EnsDb.Hsapiens.v86_2.99.0 shinyjs_2.1.0 spatstat.data_3.0-4
[29] readr_2.1.5 ggridges_0.5.6 pbapply_1.7-2 Rsamtools_2.18.0
[33] R.utils_2.12.3 parallelly_1.36.0 BSgenome_1.70.1 rstudioapi_0.15.0
[37] RSQLite_2.3.5 generics_0.1.3 BiocIO_1.12.0 gtools_3.9.5
[41] ica_1.0-3 spatstat.random_3.2-2 googlesheets4_1.1.1 dplyr_1.1.4
[45] GO.db_3.18.0 Matrix_1.6-5 fansi_1.0.6 S4Vectors_0.40.2
[49] abind_1.4-5 R.methodsS3_1.8.2 lifecycle_1.0.4 yaml_2.3.8
[53] SummarizedExperiment_1.32.0 rhdf5_2.46.1 SparseArray_1.2.3 BiocFileCache_2.10.1
[57] Rtsne_0.17 grid_4.3.2 blob_1.2.4 promises_1.2.1
[61] shinydashboard_0.7.2 crayon_1.5.2 miniUI_0.1.1.1 lattice_0.22-5
[65] cowplot_1.1.3 annotate_1.80.0 GenomicFeatures_1.54.3 KEGGREST_1.42.0
[69] pillar_1.9.0 knitr_1.45 GenomicRanges_1.54.1 rjson_0.2.21
[73] future.apply_1.11.1 codetools_0.2-19 fastmatch_1.1-4 leiden_0.4.3.1
[77] glue_1.7.0 data.table_1.15.0 remotes_2.4.2.1 vctrs_0.6.5
[81] png_0.1-8 spam_2.10-0 cellranger_1.1.0 poweRlaw_0.80.0
[85] gtable_0.3.4 cachem_1.0.8 xfun_0.41 Signac_1.12.0
[89] S4Arrays_1.2.0 mime_0.12 pracma_2.4.4 survival_3.5-7
[93] gargle_1.5.2 RcppRoll_0.3.0 ellipsis_0.3.2 fitdistrplus_1.1-11
[97] ROCR_1.0-11 nlme_3.1-164 bit64_4.0.5 progress_1.2.3
[101] filelock_1.0.3 RcppAnnoy_0.0.22 GenomeInfoDb_1.38.5 irlba_2.3.5.1
[105] KernSmooth_2.23-22 seqLogo_1.68.0 colorspace_2.1-0 BiocGenerics_0.48.1
[109] DBI_1.2.1 processx_3.8.3 tidyselect_1.2.0 bit_4.0.5
[113] compiler_4.3.2 curl_5.2.0 hdf5r_1.3.9 xml2_1.3.6
[117] desc_1.4.3 DelayedArray_0.28.0 plotly_4.10.4 rtracklayer_1.62.0
[121] caTools_1.18.2 scales_1.3.0 lmtest_0.9-40 callr_3.7.3
[125] rappdirs_0.3.3 stringr_1.5.1 digest_0.6.34 goftest_1.2-3
[129] presto_1.0.0 spatstat.utils_3.0-4 rmarkdown_2.25 XVector_0.42.0
[133] htmltools_0.5.7 pkgconfig_2.0.3 MatrixGenerics_1.14.0 dbplyr_2.4.0
[137] fastmap_1.1.1 ensembldb_2.26.0 rlang_1.1.3 htmlwidgets_1.6.4
[141] shiny_1.8.0 zoo_1.8-12 jsonlite_1.8.8 BiocParallel_1.36.0
[145] R.oo_1.26.0 RCurl_1.98-1.14 magrittr_2.0.3 GenomeInfoDbData_1.2.11
[149] dotCall64_1.1-1 Rhdf5lib_1.24.1 munsell_0.5.0 stringi_1.8.3
[153] zlibbioc_1.48.0 MASS_7.3-60.0.1 pkgbuild_1.4.3 plyr_1.8.9
[157] parallel_4.3.2 listenv_0.9.1 ggrepel_0.9.5 CNEr_1.38.0
[161] deldir_2.0-2 Biostrings_2.70.2 splines_4.3.2 tensor_1.5
[165] hms_1.1.3 BSgenome.Hsapiens.UCSC.hg38_1.4.5 ps_1.7.6 igraph_2.0.1.1
[169] spatstat.geom_3.2-8 RcppHNSW_0.6.0 reshape2_1.4.4 biomaRt_2.58.2
[173] stats4_4.3.2 TFMPvalue_0.0.9 XML_3.99-0.16.1 evaluate_0.23
[177] BiocManager_1.30.22 tzdb_0.4.0 JASPAR2020_0.99.10 httpuv_1.6.14
[181] RANN_2.6.1 tidyr_1.3.1 purrr_1.0.2 polyclip_1.10-6
[185] future_1.33.1 scattermore_1.2 rsvd_1.0.5 xtable_1.8-4
[189] restfulr_0.0.15 AnnotationFilter_1.26.0 RSpectra_0.16-1 later_1.3.2
[193] googledrive_2.1.1 viridisLite_0.4.2 tibble_3.2.1 memoise_2.0.1
[197] AnnotationDbi_1.64.1 GenomicAlignments_1.38.2 IRanges_2.36.0 cluster_2.1.6
[201] globals_0.16.2e

Hi, sorry you’re running into this issue. Could you try upgrading to the newest version of scvi-tools (1.1.0) and seeing if this issue persists?