question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(cli): Mac Homebrew-installed Node interferes with Python CDK applications

See original GitHub issue

Bug

I have a basic Python CDK application with all the dependencies installed inside a Python virtual env. From the CLI while inside the virtual env, I can cdk synth my app successfully and cdk deploy correctly starts the deployment process. However, using a cdk-deploy-to script from here, which calls npx cdk deploy, I get the following error:

Traceback (most recent call last):
  File "/REMOVED/app.py", line 4, in <module>
    from aws_cdk import (
ModuleNotFoundError: No module named 'aws_cdk'
Subprocess exited with error 1

Calling npx cdk deploy yields the same error. Somehow invoking cdk through npx is using a different environment.

Environment

  • CDK CLI Version: 1.116.0 (build d04661d)
  • Node.js Version: v14.13.1
  • OS : macOS 11.5.1
  • Language (Version): Python 3.7

This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:28 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kbakkcommented, Dec 17, 2021

Playing some more around with this, I tried changing cdk.json:

-  "app": "python3 app.py",
+  "app": "python app.py",

That results in cdk ls working as well.

Finding this a bit strange, as this command works:

python3 -c 'import aws_cdk; print(aws_cdk)'
<module 'aws_cdk' from '/Users/krisb/Code/temp/cdk_workshop/.venv/lib/python3.10/site-packages/aws_cdk/__init__.py'>

Vastly prefer this over the other workaround I mention above. Curious if this works for others here.

0reactions
github-actions[bot]commented, Jan 18, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with the AWS CDK in Python
To work with the AWS CDK, you must have an AWS account and credentials and have installed Node.js and the AWS CDK Toolkit....
Read more >
aws-cdk - Homebrew Formulae
aws-cdk. Install command: brew install aws-cdk. AWS Cloud Development Kit - framework for defining AWS infra as code. https://github.com/aws/aws-cdk.
Read more >
Lessons in AWS Python CDK: 1-Getting Started
Using npm. AWS suggests installing with npm (Node Package Manager). Thats fine. Just go to your terminal and make sure you have it...
Read more >
env: node: No such file or directory in mac - Stack Overflow
Install npm using the following command: npm install -g grunt ... I got such a problem after I upgraded my node version with...
Read more >
How to install NodeJS and NPM on Mac using Homebrew
Step 1: Install Homebrew. Homebrew is "The missing package manager for macOS". Open terminal and type the following command. $ /usr/bin/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found