cfn-lint-visual-studio-code icon indicating copy to clipboard operation
cfn-lint-visual-studio-code copied to clipboard

/bin/sh: cfn-lint: command not found when installed in virtual environment virtualenv

Open felipe1982 opened this issue 3 years ago • 7 comments

I am getting the following error when viewed in the Output window at the bottom of vscode. I have latest stable vscode, with latest stable version of cfn-lint, with latest stable version of Cloudformation Linter extension.

Settings have been updated...
Settings: {"cfnLint":{"enableAutocomplete":true,"validateUsingJsonSchema":false,"path":"cfn-lint --ignore-checks E3012 E3031","appendRules":[],"ignoreRules":[],"overrideSpecPath":""}}
Determined this file is a CloudFormation Template. file:///home/felipe/repos/sdlf-cicd/template-cicd-child-foundations.yaml. Found the string AWSTemplateFormatVersion
Running... cfn-lint --ignore-checks E3012 E3031 --format,json,--,"/home/felipe/repos/sdlf-cicd/template-cicd-child-foundations.yaml"
/bin/sh: cfn-lint: command not found

child process exited with code 127 and signal null

I have cfn-lint installed in a virtual environment ~/.venv using python -m venv ~/.venv and then pip install --upgrade cfn-lint.

  • I have selected my .venv/bin/python to be my default interpreter
  • I have tried to delete my venv, and create a new one, with same result

OS Windows 10 WSL2 OpenSUSE 15.3 cfn-lint --version cfn-lint 0.56.4 python Python 3.6.15

which cfn-lint python python3
/home/felipe/.venv/bin/cfn-lint
/home/felipe/.venv/bin/python
/home/felipe/.venv/bin/python3

VSCODE Version: 1.63.2 (user setup) Commit: 899d46d82c4c95423fb7e10e68eba52050e30ba3 Date: 2021-12-15T09:40:02.816Z Electron: 13.5.2 Chromium: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19042

felipe1982 avatar Jan 12 '22 11:01 felipe1982

I have since moved to using pipenv for my virtual environments, and I get exactly the same problem. My co-worker, who was just hired 2 weeks ago, with fresh install of VSCode and WSL2 has exactly the same problem.

felipe1982 avatar Jan 28 '22 07:01 felipe1982

You can set the path to cfn-lint in the settings of the plugin.

{
  ...
  "cfnLint.path": "/home/felipe/.venv/bin/cfn-lint"
  ...
}

We default it to cfn-lint and rely on the location being inside the Path environment variable. Depending on how you start VSCode that may or may not be available. We do allow you to override where it looks as needed using the setting above.

kddejong avatar Jan 28 '22 17:01 kddejong

I'll give it a try. Thank you. Would you happen to know what is the cause? A recent code change, or vscode change? It's been working with my virtual environment for around 4 years without fail.

felipe1982 avatar Jan 28 '22 23:01 felipe1982

I start VSCode by opening the icon on my desktop.

While setting the path in vscode settings does work, I feel that that shouldn't be the solution. pipenv and virtual environments are supported by dozens of other extensions, without having to set the path in each of them. Is there anything else can I can provide to help solve this particular problem?

felipe1982 avatar Feb 07 '22 05:02 felipe1982

You can set the path to cfn-lint in the settings of the plugin.

{
  ...
  "cfnLint.path": "/home/felipe/.venv/bin/cfn-lint"
  ...
}

We default it to cfn-lint and rely on the location being inside the Path environment variable. Depending on how you start VSCode that may or may not be available. We do allow you to override where it looks as needed using the setting above.

Unfortunately this doesn't work for the relatively common case of developing under both Windows and WSL. For working in Windows, the path needs to be ".venv\Scripts\cfn-lint", for linux under WSL it needs to be ".venv/bin/cfn-lint". The plugin really should try the configured virtual environment before falling back to PATH.

johncuyle avatar Oct 14 '23 22:10 johncuyle

I always create my virtual environment in a folder called venv and setting this worked for me:

{
  ...
  "cfnLint.path": "./venv/bin/cfn-lint"
  ...
}

dprangnell avatar Dec 26 '23 17:12 dprangnell