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

Importerror for scVI in tutorials #1464

Closed
Zethson opened this issue Mar 26, 2022 · 21 comments · Fixed by #1466
Closed

Importerror for scVI in tutorials #1464

Zethson opened this issue Mar 26, 2022 · 21 comments · Fixed by #1466
Labels

Comments

@Zethson
Copy link
Member

Zethson commented Mar 26, 2022

Describe the bug

Importerror for scVI.

To reproduce

Execute your very own tutorial: https://colab.research.google.com/github/scverse/scvi-tutorials/blob/0.15.3/api_overview.ipynb

ImportError                               Traceback (most recent call last)

[<ipython-input-4-c98868e3b7fa>](https://localhost:8080/#) in <module>()
----> 1 import scvi
      2 import scanpy as sc
      3 import matplotlib.pyplot as plt
      4 
      5 sc.set_figure_params(figsize=(4, 4))

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

Versions:

Latest stable

I suspect that this is some missmatch of incompatible versions of PyTorch and torchtext.

@adamgayoso
Copy link
Member

If I had to guess it's because the latest pyro version lower bounds torch to 1.11.0 and somehow the colab environment has an older version of torchtext, which I believe may be required by pytorch lightning

@adamgayoso
Copy link
Member

I think our options are to either wait for this googlecolab/colabtools#2668 or to upper bound pyro. I'm inclined to wait.

@DRSEI
Copy link

DRSEI commented Mar 28, 2022

Hi @adamgayoso so are you saying that I cant use the SCVI at this stage?

@Zethson
Copy link
Member Author

Zethson commented Mar 28, 2022

@adamgayoso I don't think that Google is known for solving their issues fast. IMO working tutorials (with collab) are very important and I would suggest to upper bound pyro instead of waiting.

Choice is yours ofc.

@rangan2510
Copy link

rangan2510 commented Mar 28, 2022

Presently this works:

!pip install scvi-tools==0.15.1 pyro-ppl==1.8.0 umap-learn scanpy scikit-misc leidenalg --quiet

@adamgayoso
Copy link
Member

Indeed the problem is solved if the very first thing that is done is pip install pyro-ppl==1.8.0.

@Zethson I think the solution is a scvi-colab package that is pip installed and runs the installation steps for colab...

@adamgayoso
Copy link
Member

Done.

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

This will install scvi-tools for you in google colab. We will update all the tutorials in a patch release to reflect this.

@DRSEI
Copy link

DRSEI commented Mar 28, 2022

hi @adamgayoso I am still getting the same error even through I have follow your suggestion.

%%capture
import sys

#if branch is stable, will install via pypi, else will install from source
branch = "stable"
IN_COLAB = "google.colab" in sys.modules

if IN_COLAB and branch == "stable":
!pip install scvi-tools==0.15.1
!pip install pyro-ppl==1.8.0
!pip install --quiet git+https://github.com/theislab/scib.git
elif IN_COLAB and branch != "stable":
!pip install --quiet --upgrade jsonschema

ImportError Traceback (most recent call last)
in ()
5 import scanpy as sc
6 import scib
----> 7 import scvi
8 sc.set_figure_params(figsize=(4, 4))
9

12 frames
/usr/local/lib/python3.7/dist-packages/torchtext/vocab/vocab_factory.py in ()
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

@adamgayoso
Copy link
Member

@DRSEI please check the tutorials again in a few minutes

@DRSEI
Copy link

DRSEI commented Mar 28, 2022

Thank you @adamgayoso

@bigtimecodersean
Copy link

I am running into the exact same problem as DRSEI describes above:
Running:

%%capture
import sys

#if branch is stable, will install via pypi, else will install from source
branch = "stable"
IN_COLAB = "google.colab" in sys.modules

if IN_COLAB and branch == "stable":
!pip install --quiet scvi-tools[tutorials]
elif IN_COLAB and branch != "stable":
!pip install --quiet --upgrade jsonschema
!pip install --quiet git+https://github.com/yoseflab/scvi-tools@$branch#egg=scvi-tools[tutorials]

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

gives me the following error:

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

Any ideas?

@rangan2510
Copy link

rangan2510 commented Mar 29, 2022 via email

@bigtimecodersean
Copy link

@rangan2510 I believe I am using the proposed workaround:

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

But I still get the import error?

@rangan2510
Copy link

For me, this worked on Kaggle. You may try it out.
!pip install scvi-tools==0.15.1 pyro-ppl==1.8.0 umap-learn scanpy scikit-misc leidenalg --quiet

@bigtimecodersean
Copy link

Thanks, I successfully ran the above ^:
!pip install scvi-tools==0.15.1 pyro-ppl==1.8.0 umap-learn scanpy scikit-misc leidenalg --quiet

However the following:

import scvi
import scanpy as sc
import matplotlib.pyplot as plt

sc.set_figure_params(figsize=(4, 4))

for white background of figures (only for docs rendering)

%config InlineBackend.print_figure_kwargs={'facecolor' : "w"}
%config InlineBackend.figure_format='retina'

As well as:

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

Both give me the import error.

I am thinking it might have something to do with a PyTorch dependency?

Screenshot 2022-03-28 at 21 07 11

I am running PyTorch: '1.11.0+cu102'

@rangan2510
Copy link

@bigtimecodersean I believe it's something else. I am sharing a link to a notebook I have on Colab and it works fine. Did a !pip freeze so you can check the versions: scVI import.ipynb

@bigtimecodersean
Copy link

@rangan2510 Thanks for the help. I just ran your code line by line and got the exact same import error on the:

"import scvi" line in your second block. Bizarre

@bigtimecodersean
Copy link

Starting a new notebook solved the problem with your solution @rangan2510 Thank you so much!!!

@adamgayoso
Copy link
Member

@bigtimecodersean

%%capture
import sys

#if branch is stable, will install via pypi, else will install from source
branch = "stable"
IN_COLAB = "google.colab" in sys.modules

if IN_COLAB and branch == "stable":
!pip install --quiet scvi-tools[tutorials]
elif IN_COLAB and branch != "stable":
!pip install --quiet --upgrade jsonschema
!pip install --quiet git+[https://github.com/yoseflab/scvi-tools@$branch#egg=scvi-tools[tutorials]](https://github.com/yoseflab/scvi-tools@$branch#egg=scvi-tools%5Btutorials%5D)

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

should instead only be

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

I don't believe this new code will work in kaggle unless you run it like

!pip install --quiet scvi-colab
from scvi_colab import install
install(run_outside_colab=True)

@rangan2510
Copy link

rangan2510 commented Oct 11, 2022 via email

@michaelmather15
Copy link

Hi. I am hoping to ask a question related to the above point please. I had scVI working fine in Colab a few months ago but when I have come back to it today, when I run

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

I get the following message:

INFO scvi-colab: Installing scvi-tools.
INFO scvi-colab: Install successful. Testing import.

AssertionError Traceback (most recent call last)
in <cell line: 3>()
1 get_ipython().system('pip install --quiet scvi-colab')
2 from scvi_colab import install
----> 3 install()

9 frames
/usr/local/lib/python3.10/dist-packages/pyro/distributions/torch_patch.py in
8 import torch
9
---> 10 assert torch.version.startswith("1.")
11
12

AssertionError:

If I do !pip freeze after this it looks like scvi has indeed installed. But then when I run import scvi I get the exact same error message as above. I've also tried this in a fresh notebook.

Does anyone know why this is happening please? Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants