GoekeLab / m6anet

Detection of m6A from direct RNA-Seq data
https://m6anet.readthedocs.io/
MIT License
101 stars 17 forks source link

ImportError: cannot import name 'TypeAlias' from 'typing_extensions' (/usr/lib/python3/dist-packages/typing_extensions.py) #59

Closed matthewstuartedwards closed 1 year ago

matthewstuartedwards commented 1 year ago

Hi, I was running m6anet and got to the inference step when I encountered this error. Here's the output.

  Traceback (most recent call last):
    File "/home/matthew/.local/bin/m6anet-run_inference", line 5, in <module>
      from m6anet.scripts.run_inference import main
    File "/home/matthew/.local/lib/python3.8/site-packages/m6anet/scripts/run_inference.py", line 2, in <module>
      import torch
    File "/home/matthew/.local/lib/python3.8/site-packages/torch/__init__.py", line 753, in <module>
      from .serialization import save, load
    File "/home/matthew/.local/lib/python3.8/site-packages/torch/serialization.py", line 18, in <module>
      from typing_extensions import TypeAlias
  ImportError: cannot import name 'TypeAlias' from 'typing_extensions' (/usr/lib/python3/dist-packages/typing_extensions.py)

Looked like a simple import error, and sure enough if I installed cast_control, the error disappeared.

sudo python3 -m pip install cast_control

Just letting you know so you can update your pip build configuration with this library.

chrishendra93 commented 1 year ago

hi @matthewstuartedwards, thanks a lot for pointing this out. I will make sure to update the build configuration with this. I think all this while I have been using miniconda and that package might have been preinstalled in the environment

chrishendra93 commented 1 year ago

hi @matthewstuartedwards , just want to check with you, how does installing cast_control solve this? The package https://github.com/alexdelorenzo/cast_control says "castcontrol is [a daemon](https://en.wikipedia.org/wiki/Daemon(computing)) utility that allows you to control media playback on casting devices from the Linux desktop." Maybe this fixes the error related to other packages by installing some required dependencies?

Your error log seems to suggest that it is related with pytorch. Can I check your pytorch version?

matthewstuartedwards commented 1 year ago

I thought with an error importing TypeAlias, cast_control had something to do with casting variables to a type. But you're correct that that is a different project.

I didn't record what packages got upgraded when I installed cast_control, so I cannot tell you what version of pytorch I had when I experienced this error. This is my current version:


python3 -m pip show --version torch
Name: torch
Version: 1.13.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/matthew/.local/lib/python3.8/site-packages
Requires: nvidia-cublas-cu11, typing-extensions, nvidia-cuda-runtime-cu11, nvidia-cudnn-cu11, nvidia-cuda-nvrtc-cu11
Required-by: m6anet

Looking at what is required by cast_control, the package typing-extensions stands out. And indeed this is the package that has a type called TypeAlias.

python3 -m pip show --version cast_control
Name: cast-control
Version: 0.11.8.post0
Summary: 📺 Control Chromecasts from Linux and D-Bus
Home-page: https://github.com/alexdelorenzo/cast_control
Author: None
Author-email: None
License: AGPL-3.0
Location: /usr/local/lib/python3.8/dist-packages
Requires: appdirs, daemons, pydbus, click, PyChromecast, PyGObject, mpris-server, typing-extensions, aiopath
Required-by:

And looking at typing-extensions shows that it is required by PyTorch, but maybe this is where the versions need to match up.

python3 -m pip show --version typing-extensions
Name: typing-extensions
Version: 4.4.0
Summary: Backported and Experimental Type Hints for Python 3.7+
Home-page: None
Author: None
Author-email: "Guido van Rossum, Jukka Lehtosalo, Łukasz Langa, Michael Lee" <levkivskyi@gmail.com>
License: None
Location: /usr/local/lib/python3.8/dist-packages
Requires:
Required-by: torch, mpris-server, cast-control, aiopath

Looking at the source code for typing_extensions, I can see that the original problem I had in TypeAlias was added to the source code about 2 years ago in version 3.10.0.0. So without being able to check for sure, I think this is the minimum version of typing-extensions needed.

chrishendra93 commented 1 year ago

hi @matthewstuartedwards, thanks for checking this. Looking at https://pypi.org/project/typing-extensions/,

"The typing_extensions module serves two related purposes:

So I'm guessing this is related to the newer TypeGuard in python 3.10 that PyTorch 1.13.0 might use. On the other hand, for PyTorch 1.6.0:

Name: torch
Version: 1.6.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/christopherhendra/miniconda3/envs/m6anet_master/lib/python3.8/site-packages/torch-1.6.0-py3.8-linux    -x86_64.egg
Requires: future, numpy
Required-by: m6anet

I have fixed the torch installation to 1.6.0 in the latest release. Can you try cloning the master branch and see if the same error persists without installing cast_control?

Thank you!

matthewstuartedwards commented 1 year ago

Sorry, I don't really have a setup for reverting my python environment to try this out. If it happens again though, I'll try to document it better.

The computer I was installing m6anet on was using Ubuntu 20.04, so only at python 3.8.

chrishendra93 commented 1 year ago

okay got it, I think the latest update with pytorch 1.6.0 on both Python 3.7 and 3.8 should work. Closing this issue for now, let me know if you find any problem of a similar nature