J.S
J.S

Reputation: 159

After successful installation aws-cdk, cdk command not found

I am installing aws-cdk on windows using powershell,

First I was getting Error : "\AppData\Roaming\npm' npm ERR! enoent This is related to npm not being able to find a file."

during installation. I fixed that by creating folder "\AppData\Roaming\npm" as recommended by some solution.

Now my installation is successful with "npm i -g aws-cdk". No error reported,

but when I do "cdk --version" I am getting "cdk : The term 'cdk' is not recognized as the name of a cmdlet, function, script file, or operable program."

"npm -g ls --depth=0" returns C:\Users<username>\AppData\Roaming\npm `-- [email protected]

Upvotes: 9

Views: 14763

Answers (8)

python enthusiast
python enthusiast

Reputation: 3

How to Install CDK in PyCharm

Problem: Unable to install CDK in PyCharm.

Solution:

  1. Create a new directory and initialize a CDK app:

    mkdir test-cdk
    cd test-cdk
    cdk init app --language python
    
  2. Activate the virtual environment:

    source .venv/bin/activate
    
  3. Install dependencies:

    python -m pip install -r requirements.txt
    
  4. Open the project in PyCharm:

    • File > Open > (absolute path to test-cdk)
  5. Configure PyCharm's Python interpreter:

    • CTRL + ALT + S > Cog Icon > Add…
    • Check either "New environment" or "Existing environment"
    • Click the Elipsis icon to select the appropriate interpreter.

Note: Ensure that your virtual environment is activated before running PyCharm to access the installed CDK packages.

Upvotes: 0

Dewz
Dewz

Reputation: 264

Adding the following to the path variable within the user environment variables and restarting the terminal worked for me:

%USERPROFILE%\AppData\Roaming\npm;

Upvotes: 0

Adam Hughes
Adam Hughes

Reputation: 16309

On windows, make sure you don't have two versions of node in your path. For example, after installing latest node, I was having issues with cdk. Then I typed

where.exe node

Only to find it had been installed implicitly with another windows program

C:\Program Files\Microsoft HPC Pack 2012\Bin\node.exe 

I had to put the correct node earlier in the path - the order of path variables determines priority.

Upvotes: 0

Surajan Shrestha
Surajan Shrestha

Reputation: 61

I used npx cdk --version instead of cdk --version and it worked.

Upvotes: 3

Chiel
Chiel

Reputation: 2169

If you made the mistake of installing cdk with pip at some point in time, make sure to remove it.

pip uninstall cdk

You could check if you have it installed with:

pip list | grep cdk

Upvotes: -1

Ramakrishna Reddy
Ramakrishna Reddy

Reputation: 99

  1. Install AWS-CDK:

    npm i -g aws-cdk
    
  2. run below command to set path of environment variable:

    setx PATH "D:\Users\<username>\AppData\Roaming\npm"
    
  3. close the command prompt once above command successfully executed.

  4. open command prompt as new session and run below command:

    cdk --version
    

Upvotes: 9

J.S
J.S

Reputation: 159

The above solution may work, but I was able to make mine work by adding "\AppData\Roaming\npm" to user Path variable.

Upvotes: 2

Trott
Trott

Reputation: 70075

There are many reasons this could be happening, some of them likely Windows-specific. It is probably worth it to chase down the issue, but for a quick "just get the command running" solution, you can use npx to install-and-execute rather than npm to install.

$ npx -p aws-cdk cdk --version
1.72.0 (build c2f38e8)
$

Upvotes: 8

Related Questions