Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named aws_cdk

When I run cdk deploy, I get the following error:

Traceback (most recent call last):
  File "app.py", line 3, in <module>
    from aws_cdk import core
ModuleNotFoundError: No module named 'aws_cdk'

I installed cdk with npm

npm install -g aws-cdk

I activated the virtual env by

source .env/bin/activate

I'm using python3.8. I installed aws_cdk dependencies by

pip install -r requirements.txt

When editing the python files, I am able to import aws_cdk and run individual functions successfully. I think the problem is that cdk is located in the /usr directory:

> which cdk
/usr/local/bin/cdk

And I think it's using python from my /usr/bin instead of virtual env. How do I make cdk use python in my virtual environment?

EDIT:

requirements.txt

-e .
like image 922
MoneyBall Avatar asked Jul 29 '20 09:07

MoneyBall


People also ask

Does Python support CDK?

Python is a fully-supported client language for the AWS CDK and is considered stable. Working with the AWS CDK in Python uses familiar tools, including the standard Python implementation (CPython), virtual environments with virtualenv , and the Python package installer pip .

How does CDK deploy work?

The cdk deploy subcommand deploys one or more specified stacks to your AWS account. The CDK Toolkit runs your app and synthesizes fresh AWS CloudFormation templates before deploying anything. Therefore, most command line options you can use with cdk synth (for example, --context ) can also be used with cdk deploy .

What is CDK synthesize?

The cdk synth command from the CDK CLI generates and prints the CloudFormation equivalent of the CDK stack we've defined. The code we write in our CDK applications gets compiled down to CloudFormation before it gets deployed.

How do I uninstall AWS CDK?

In order to delete a CDK stack, we have to use the cdk destroy command. Copied! If we have more than 1 stack in our CDK app, we have to explicitly specify the name of the stack we want to delete.


2 Answers

install via cmd as below.

pip install aws-cdk.core

or

add following line in requirements.txt file

aws-cdk.core

it should resolved

like image 78
Shahabaj S. Shaikh Avatar answered Sep 23 '22 19:09

Shahabaj S. Shaikh


I think you have to order

python -m pip install -r requirements.txt

This will install the standard dependencies for your CDK project.

like image 27
P. Str Avatar answered Sep 22 '22 19:09

P. Str