In python 3.8.0, when you attempt to run any cdk cli functions, you end up with the following import error:
Traceback (most recent call last):
File "app.py", line 3, in <module>
from aws_cdk import core
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/aws_cdk/core/__init__.py", line 6, in <module>
import jsii
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/__init__.py", line 4, in <module>
from ._runtime import (
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/_runtime.py", line 6, in <module>
from jsii import _reference_map
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/_reference_map.py", line 6, in <module>
from ._kernel.types import JSClass, Referenceable
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/_kernel/__init__.py", line 15, in <module>
from jsii._kernel.providers import BaseProvider, ProcessProvider
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/_kernel/providers/__init__.py", line 2, in <module>
from jsii._kernel.providers.process import ProcessProvider
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 15, in <module>
import cattr # type: ignore
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/cattr/__init__.py", line 2, in <module>
from .converters import Converter, UnstructureStrategy
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/cattr/converters.py", line 15, in <module>
from ._compat import (
File "/Users/***/.local/share/virtualenvs/***/lib/python3.8/site-packages/cattr/_compat.py", line 86, in <module>
from typing import _Union
ImportError: cannot import name '_Union' from 'typing' (/Users/***/.pyenv/versions/3.8.0/lib/python3.8/typing.py)
Subprocess exited with error 1
This does not happen in python 3.7.4. I have opened a bug report in the jsii module: https://github.com/aws/jsii/issues/913.
Given python 3.8.0 is installed:
cdk ls
Initial fix should be to only allow python 3.7 until the jsii bug is fixed.
This is :bug: Bug Report
This will be fixed very soon! The fix for this is in aws/jsii#1177
Python 3.8.0 seems to working fine for me now. I had issues earlier, but I cannot reproduce it using the current version.
@henrist thanks for confirming. As @RomainMuller mentioned, the fix was published with jsii 0.21.1 and the cdk >= 1.22.0 should be working.
Please reopen if there are any unresolved issues or questions.
I am having this issue with python 3.9.
@vennemp It's the same thing because of cattr dependency, which doesn't support Python 3.9 yet (but it's almost here) - https://github.com/Tinche/cattrs/issues/100 :smiley:
Most helpful comment
I am having this issue with python 3.9.