BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
324 stars 58 forks source link

Errors while running colab tutorial #136

Closed narein97 closed 2 years ago

narein97 commented 2 years ago

On running the colab tutorial a message pops up saying "cell2loc_env2 is not recognized. Switching to python3". The environment then switches to python3. Following this are import issues (understably so). Could someone take a look at this ?

vitkl commented 2 years ago

Hi @narein97

Does this only happen in Colab platform? Most likely the installation procedure needs changing (maybe it would works if cell2location was installed in the default environment). If anyone else can look into this or if you solved this and share a solution - would be great.

vitkl commented 2 years ago

Actually, your error can be solved simply by changing the environment name in the change runtime type dialogue. However, I get various errors related to package installation:

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchvision 0.11.1+cu111 requires torch==1.10.0, but you have torch 1.11.0 which is incompatible.
torchtext 0.11.0 requires torch==1.10.0, but you have torch 1.11.0 which is incompatible.
torchaudio 0.10.0+cu111 requires torch==1.10.0, but you have torch 1.11.0 which is incompatible.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-1-b7a7dc08bcde>](https://localhost:8080/#) in <module>()
     12 import matplotlib as mpl
     13 
---> 14 import cell2location
     15 import scvi
     16 

17 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.
---------------------------------------------------------------------------
vitkl commented 2 years ago

Looks like Colab changed their main GPU drivers so you need to modify the installation procedure to pip install versions compatible with their CUDA software before installing cell2location:

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu111
yxiaobme commented 2 years ago

I am also facing similar issues when running the tutorial in Colab. The solution from vitkl doesn't solve the problem.

After I saw the error messages above, I downgraded a bunch of packages by the following command

!pip install torch==1.10.0 pyro-ppl==1.8.0 tf-estimator-nightly==2.8.0.dev2021122109 albumentations==0.1.10

The installation passed but import cell2location crashed every time. There is no clue how to solve it since it is a segment fault. I got the following messages when I run the import cell2location in the python cli under the terminal of the Colab:

_find_and_load
  File "/usr/local/lib/python3.7/dist-packages/cell2location/__init__.py", line 5 in <module>
  File "<frozen importlib._bootstrap>", line 219 in
_call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 728 in exec_module
  File "<frozen importlib._bootstrap>", line 677 in
_load_unlocked
  File "<frozen importlib._bootstrap>", line 967 in
_find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 983 in
_find_and_load
  File "<stdin>", line 1 in <module>
Segmentation fault (core dumped)
narein97 commented 2 years ago

Quick update: This worked for me. I guess it's more of a hack than a solution, As vitkl suggested, I performed the following to resolve the error