Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'anndata' #38

Closed
mbahin opened this issue Feb 16, 2021 · 5 comments
Closed

ModuleNotFoundError: No module named 'anndata' #38

mbahin opened this issue Feb 16, 2021 · 5 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@mbahin
Copy link

mbahin commented Feb 16, 2021

Hi,

I'm trying to convert a SCE object to an AnnData one in R but I get the following message:

> library(zellkonverter)
> library(anndata)
> adata <- SCE2AnnData(sce)
Error in py_module_import(module, convert = convert) : 
  ModuleNotFoundError: No module named 'anndata'

Detailed traceback: 
  File "/home/mathieu/R/x86_64-conda-linux-gnu-library/4.0/reticulate/python/rpytools/loader.py", line 24, in _import_hook
    level=level

Any clue on that problem?

Cheers,
Mathieu

SessionInfo:

R version 4.0.3 (2020-10-10)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: Debian GNU/Linux 10 (buster)

Matrix products: default
BLAS/LAPACK: /opt/miniconda3/lib/libopenblasp-r0.3.12.so

locale:
[1] C

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

other attached packages:
[1] anndata_0.7.5.1     zellkonverter_1.0.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6                  XVector_0.30.0             
 [3] rappdirs_0.3.3              GenomicRanges_1.42.0       
 [5] BiocGenerics_0.36.0         zlibbioc_1.36.0            
 [7] IRanges_2.24.1              lattice_0.20-41            
 [9] R6_2.5.0                    GenomeInfoDb_1.26.2        
[11] tcltk_4.0.3                 tools_4.0.3                
[13] SummarizedExperiment_1.20.0 parallel_4.0.3             
[15] grid_4.0.3                  Biobase_2.50.0             
[17] basilisk_1.2.1              matrixStats_0.58.0         
[19] assertthat_0.2.1            Matrix_1.3-2               
[21] GenomeInfoDbData_1.2.4      BiocManager_1.30.10        
[23] S4Vectors_0.28.1            bitops_1.0-6               
[25] basilisk.utils_1.2.2        RCurl_1.98-1.2             
[27] SingleCellExperiment_1.12.0 DelayedArray_0.16.1        
[29] compiler_4.0.3              filelock_1.0.2             
[31] MatrixGenerics_1.2.1        stats4_4.0.3               
[33] jsonlite_1.7.2              reticulate_1.18
@lazappi lazappi added the bug Something isn't working label Feb 17, 2021
@lazappi
Copy link
Member

lazappi commented Feb 17, 2021

Hi @mbahin

{zellkonverter} currently converts between an R SingleCellExperiment and a Python AnnData object, not an R AnnData object from the {anndata} package.

The error you are seeing is because the Python anndata library is not installed in your Python environment. The {reticulate} documentation has useful information for managing a Python environment for R https://rstudio.github.io/reticulate/.

Alternatively, you can use the writeH5AD() function in {zellkonverter} which will manage the environment creation process for you and give you a .h5ad file on disk. You can then read this into R using {anndata} if you want an R AnnData object.

@lazappi lazappi closed this as completed Feb 17, 2021
@LTLA
Copy link
Contributor

LTLA commented Feb 17, 2021

Might consider exporting the BasiliskEnvironment objects so people can just:

library(basilisk)
library(zellkonverter)
basiliskStart(zellkonverterEnv) # give it a nice name.

ad <- SCE2AnnData(sce)

This is technically not safe against displacement from other Python instances - one would have to wrap further code in basiliskRun() to be properly protected - but it should be good enough for ad hoc scripts written by end-users.

@lazappi lazappi reopened this Feb 17, 2021
@mbahin
Copy link
Author

mbahin commented Feb 17, 2021

Thanks for your answers.
The writeH5AD() approach worked! :)

@mbahin mbahin closed this as completed Feb 17, 2021
@lazappi
Copy link
Member

lazappi commented Feb 18, 2021

Great! 👍🏻

Reopening as a note to think about exporting the environment objects.

@lazappi lazappi reopened this Feb 18, 2021
@lazappi lazappi added the enhancement New feature or request label Feb 18, 2021
@lazappi
Copy link
Member

lazappi commented Mar 5, 2021

Environment now exported in devel as of v1.1.5

@lazappi lazappi closed this as completed Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants