Search code examples
pythonpython-3.xgoogle-colaboratorytype-aliasalpaca

Alpaca on Google colab: cannot import name 'TypeAliasType' from 'typing_extensions'


I'm trying to use alpaca (the trading platform) on google colab. It works locally on my laptop, but I get the following error:

ImportError                               Traceback (most recent call last)
<ipython-input-4-791aac88b96e> in <cell line: 16>()
     14 # from alpaca.data.historical import CryptoHistoricalDataClient
     15 
---> 16 from alpaca.data.historical import StockHistoricalDataClient
     17 
     18 import alpaca

9 frames
/usr/local/lib/python3.10/dist-packages/pydantic/_internal/_typing_extra.py in <module>
     11 from typing import TYPE_CHECKING, Any, ForwardRef
     12 
---> 13 from typing_extensions import Annotated, Final, Literal, TypeAliasType, TypeGuard, get_args, get_origin
     14 
     15 if TYPE_CHECKING:

ImportError: cannot import name 'TypeAliasType' from 'typing_extensions' (/usr/local/lib/python3.10/dist-packages/typing_extensions.py)

Does anyone know what's causing this?

This is the only lines I have in colab before I hit this error:

!pip install transformers
!pip install alpaca-py    
from alpaca.data.historical import StockHistoricalDataClient

Solution

  • Just delete the runtime and run your implementation again.