Python gives you the ImportError: No module named 'typing'
message when the typing
module is not found in Python or it’s not installed.
To fix this error, you need to make the typing
module available. Let’s see how in this article.
The typing
module provides runtime support for type hints. It’s a built-in module in Python 3.5 and later versions, but not included in earlier versions of Python.
When you run import typing
or install a package that requires the typing
module, you’ll see the following error:
Traceback (most recent call last):
File...
from typing import List, Optional
ImportError: No module named typing
To fix this error, you can either upgrade your Python version or install the stand-alone typing
package from pip
.
To install the stand-alone typing
package, run one of the following pip install
commands:
# Use pip to install typing
pip install typing
# Or pip3
pip3 install typing
# For Windows
py install typing
# If pip isn't available in PATH
python -m pip install typing
# Or with python3
python3 -m pip install typing
# For Windows without pip in PATH
py -m pip install typing
# for Anaconda
conda install -c anaconda typing
# for Jupyter Notebook
!pip install typing
# If you see permission denied error
pip install typing --user
Once you installed the typing
package, the ImportError
message should disappear.
If that doesn’t work, then you can try to upgrade your pip
version before installing again.
Use the one of the following commands to upgrade pip:
# if pip available from command line
pip install --upgrade pip
# for pip3
pip3 install --upgrade pip
# if pip not available from command line
python -m pip install --upgrade pip
# python3
python3 -m pip install --upgrade pip
# Windows
py -m pip install --upgrade pip
Alternatively, you can download the get-pip.py
file manually from the pypa.io website:
- For Python 3.6 download at https://bootstrap.pypa.io/pip/3.6/
- For Python 3.5 download at https://bootstrap.pypa.io/pip/3.5/
- For Python 3.4 download at https://bootstrap.pypa.io/pip/3.4/
- For Python 2.7 download at https://bootstrap.pypa.io/pip/2.7/
Once you downloaded the get-pip.py
file, open the terminal at the location where you have the downloaded script.
You need to run one of the commands below:
# For Linux / macOS
python get-pip.py
# using python3
python3 get-pip.py
# For Windows
py get-pip.py
After installing the right pip
version, continue with installing the typing
package if you have Python version less than 3.5.
Once you have the typing
package, this error would be resolved.