[Solved] ImportError: No Module Named Typing

When you try to install some packages, you might get ImportError: No module named typing error. Actually what this error is telling is that your python version is outdated.

Traceback (most recent call last):
   File "/usr/local/bin/pip", line 11, in 
     load_entry_point('pip==21.1.1', 'console_scripts', 'pip')()
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 489, in load_entry_point
     return get_distribution(dist).load_entry_point(group, name)
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2843, in load_entry_point
     return ep.load()
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2434, in load
     return self.resolve()
   File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 2440, in resolve
     module = __import__(self.module_name, fromlist=['__name__'], level=0)
   File "/Library/Python/2.7/site-packages/pip-21.1.1-py2.7.egg/pip/__init__.py", line 1, in 
     from typing import List, Optional
 ImportError: No module named typing
Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 171, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pip.exe\__main__.py", line 5, in 
  File "C:\Python34\lib\site-packages\pip\__init__.py", line 1, in 
    from typing import List, Optional
ImportError: No module named 'typing'

In both of these error traces, Python version seems to be old. Pip (Package Installer for Python) is trying to import List, Optional from typing module. But typing module is added to Python in version 3.5 (https://docs.python.org/3/library/typing.html).

You can check your Python version with the following command:

python --version

If you are working in Conda environment, you can update your Python version. Note that, this command will also update dependencies.

conda update python

If you want to work on a clean, new environment, you can create an environment specifying Python version.

conda create -n python38 python=3.8

Trying to install typing module is misleading. You will get a similar error, because pip needs typing module in the first place. Without it you cannot start pip. So the best solution is updating your Python version and typing module will be ready to use.