I have recently been asked to learn the AWS-CDK module in Python to handle deployments and following the examples on in the AWS-CDK documentation I am getting an error that indicates it cannot import 'core'
I have created a virtual environment that is using Python 3.6.6 and am running CDK version 1.16.2 (build 5893301) all running on a Windows 10 64-bit machine in VSCode
from aws_cdk import core
I would expect this to just load the constructor but it just returns the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'core'
I have searched and searched and I cannot seem to find what I am doing wrong or anything that contradicts the documentation on the CDK site. Any insight would be appreciated.
This worked for me. Might be related to conda / venv interactions.
pip3 install -r requirements.txt --user
Is aws_cdk.core installed in your environment? I have this:
pip list|grep core
aws-cdk.core 1.68.0
I noticed that the cdk.json "app" value can also generate this error.
Example of the cdk.json file which used to generate the error:
{
"app": "python3 app.py",
"context": {
...
}
}
Changing the app value from python3 to python resolved the problem for me. Like this:
{
"app": "python app.py",
"context": {
...
}
}
I am not entirely sure why this happens as I am using python 3.8 and I can see a python.exe in the python path/environment variables. If I deactivate the virtual env, and I have cdk installed globally, this problem goes away regardless of whether I use python or python3 for the app value. Therefore, I suspect it's got to do something with environment paths.
aws-cdk-lib==2.34.0
constructs>=10.0.0,<11.0.0
aws-cdk.aws-kinesisfirehose-alpha
aws_cdk.aws-kinesisfirehose-destinations-alpha
aws_cdk.core
pip list|grep core
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.