scverse / scvi-tools

Deep probabilistic analysis of single-cell and spatial omics data
http://scvi-tools.org/
BSD 3-Clause "New" or "Revised" License
1.23k stars 349 forks source link

ImportError in Colab #1486

Closed bitcometz closed 2 years ago

bitcometz commented 2 years ago

Hello, I try to run the toturial with the following URL: https://colab.research.google.com/drive/1V4BD3SAGDwLzvMUn90FMOHYVNG_iP4Ee?usp=sharing

But I met some errors:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-6-0189c31d4fff>](https://localhost:8080/#) in <module>()
      1 import anndata
----> 2 import scvi
      3 import scanpy as sc
      4 import numpy as np
      5 

12 frames
[/usr/local/lib/python3.7/dist-packages/torchtext/vocab/vocab_factory.py](https://localhost:8080/#) in <module>()
      2 from typing import Dict, Iterable, Optional, List
      3 from collections import Counter, OrderedDict
----> 4 from torchtext._torchtext import (
      5     Vocab as VocabPybind,
      6 )

ImportError: /usr/local/lib/python3.7/dist-packages/torchtext/_torchtext.so: undefined symbol: _ZNK3c104Type14isSubtypeOfExtERKSt10shared_ptrIS0_EPSo

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------
import anndata
import scvi
import scanpy as sc
import numpy as np

# can set the DPI on save here
sc.set_figure_params(figsize=(6, 6), frameon=False)
sc.settings.n_jobs=2

Could you help with this problem ?

Thanks !!!

adamgayoso commented 2 years ago

Hello, please delete the cell with the current installation commands and replace with the first cell shown here

bitcometz commented 2 years ago

Thanks !!! there are some codes need to be changed.

## for installation
!pip install --quiet scvi-colab
from scvi_colab import install
install()

## change the  matplotlib version
!python -m pip uninstall matplotlib
!pip install matplotlib==3.1.3
!pip install bbknn

# adata = scvi.data.spleen_lymph_cite_seq(run_setup_anndata=False)
# replace by the following code
adata = scvi.data.spleen_lymph_cite_seq() # default is True. Will set it up for you
adata.obs_names_make_unique()

# scvi.data.setup_anndata(adata, layer="counts", batch_key='batch')
scvi.model.SCVI.setup_anndata(adata, layer="counts", batch_key="batch")

# scvi.data.view_anndata_setup(adata)
model.view_anndata_setup(adata)

but I still got some errors:

sc.pl.umap( adata, color=["Ly6d", "Xcr1", "Foxp3"]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-79-00f769552dfd>](https://localhost:8080/#) in <module>()
----> 1 sc.pl.umap(adata, color=["Ly6d", "Xcr1", "Foxp3"], layer="scvi_expr")

5 frames
[/usr/local/lib/python3.7/dist-packages/matplotlib/colorbar.py](https://localhost:8080/#) in __init__(self, ax, mappable, **kw)
   1181                 kw['alpha'] = mappable.get_alpha()
   1182 
-> 1183             ColorbarBase.__init__(self, ax, **kw)
   1184 
   1185     def on_mappable_changed(self, mappable):

TypeError: __init__() got an unexpected keyword argument 'location'
scandata.obs[["labels_for_scanvi"]].value_counts()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
[<ipython-input-93-77982d7b5115>](https://localhost:8080/#) in <module>()
----> 1 scandata.obs[["labels_for_scanvi"]].value_counts()

2 frames
[/usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py](https://localhost:8080/#) in _validate_read_indexer(self, key, indexer, axis)
   1372                 if use_interval_msg:
   1373                     key = list(key)
-> 1374                 raise KeyError(f"None of [{key}] are in the [{axis_name}]")
   1375 
   1376             not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())

KeyError: "None of [Index(['labels_for_scanvi'], dtype='object')] are in the [columns]"

Best

adamgayoso commented 2 years ago

We confirmed that indeed it works now, I would remove any extra pip installs that you added.