stackstac on Google Colab results in ImportError: cannot import name 'Protocol' from 'typing'

stackstac on Google Colab results in ImportError: cannot import name 'Protocol' from 'typing'

我无法在 Google Colab 上安装 stackstac。这可以用下面的代码重现。

!pip install stackstac
import stackstac

输出:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-c01f370957f7> in <module>()
      1 get_ipython().system('pip install stackstac')
----> 2 import stackstac

1 frames
/usr/local/lib/python3.7/dist-packages/stackstac/rio_reader.py in <module>()
      5 import threading
      6 import weakref
----> 7 from typing import TYPE_CHECKING, Optional, Protocol, Tuple, Type, Union
      8 
      9 import numpy as np

ImportError: cannot import name 'Protocol' from 'typing' (/usr/lib/python3.7/typing.py)

---------------------------------------------------------------------------

那个解决方案怎么不翻译。

从 Python 3.8 开始,

Protocol 被引入 typing,可以看出 in the docs。根据您的文件路径,您似乎是 运行 Python 3.7 - 如果可以,升级到使用 Python 3.8 或更高版本。