CDK: Cannot find module in python project

0

I have a CDK python project that I am trying to bootstrap. When I run the bootstrap command cdk bootstrap --profile <my profile> I get the following error:

RuntimeError: Cannot find module '@aws-cdk/cx-api'

My requirements.txt shows:

aws-cdk-lib
constructs
aws-cdk.aws-redshift
aws_cdk.cx_api

Running pip list shows: Package Version


attrs 23.2.0 aws-cdk.asset-awscli-v1 2.2.202 aws-cdk.asset-kubectl-v20 2.1.2 aws-cdk.asset-node-proxy-agent-v6 2.0.3 aws-cdk.aws-redshift 0.28.0 aws-cdk.cdk 0.28.0 aws-cdk.cx-api 0.28.0 aws-cdk-lib 2.138.0 ....

So it's clear to me that my python environment has aws-cdk.cx-api, but it seems the cdk cli command somehow does not have access to the module?

I'm sure this is a rookie mistake, but I'm at a loss.

질문됨 6달 전393회 조회
1개 답변
0
수락된 답변

1. Environment Check First, ensure that the environment where your CDK CLI is running is the same as where your Python packages are installed. If you're using virtual environments (like venv or conda), make sure the environment is activated when running the CDK commands.

# Activate your virtual environment (if using one)
source /path/to/venv/bin/activate  # On Unix or macOS
.\path\to\venv\Scripts\activate    # On Windows

# Then try running the bootstrap command
cdk bootstrap --profile <your-profile>

**2. Correct Module Names in requirements.txt ** aws-cdk.cx-api instead of your aws_cdk.cx_api https://pypi.org/project/aws-cdk.cx-api/

3. Environment Variables Sometimes, environment variables can cause issues if they point to different Python environments. Check if there are any such variables set:

echo $PYTHONPATH  # Unix/macOS
echo %PYTHONPATH%  # Windows

If PYTHONPATH is set, ensure it does not conflict with your current environment.

4. Check CDK CLI Installation Ensure that your AWS CDK CLI is correctly installed and up-to-date. Sometimes, the CLI may be installed globally but needs to be aware of the local Python environment.

npm install -g aws-cdk
profile picture
전문가
답변함 6달 전
  • Thank you for the response. I verified all these things were correct. I'm still not sure what the core problem was, however by starting with a fresh requirements.txt I was able to move past it. I'm now locking in versions of my dependencies and things are looking much better. I'm going to accept your answer, as I think it will help others, but I wanted to note here that my issue was apparently something else...

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠