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.

Tejay
demandé il y a 25 jours53 vues
1 réponse
0
Réponse acceptée

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
EXPERT
répondu il y a 25 jours
  • 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...

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions