Conda ImportError when trying to run python file
conda
error
terminal
Update
typing_extensions
when getting ImportError
Traceback (most recent call last):
...
from typing_extensions import TypeAlias # Python 3.10+ ImportError: cannot import name 'TypeAlias' from 'typing_extensions' (/opt/homebrew/Caskroom/miniforge/base/envs/my_env/lib/python3.10/site-packages/typing_extensions.py)
Steps to reproduce error
- Open terminal
- Create requirements.txt in current working directory
# requirements.txt
typing-extensions ==3.7.4
- Create new environment with python=3.10, install pip, install required libraries from requirements.txt using pip. Here, our environment is called
my_env
.
conda create -n myenv python=3.10
conda install pip
pip install -r requirements.txt
- Create a dummy python file called run.py in current working directory
# run.py
print('hello world!')
- Run run.py from terminal
python run.py
How to fix it
Upgrade typing_extensions by:
pip install typing_extensions==4.7.1 --upgrade