title: npm install npm ERR! gyp verb `which` failed Error: not found: python2
body: <p>On Ubuntu 21.10, where Python2.x is actually not installed, I'm facing the following error when executing &quot;npm install&quot; on a large project (the <code>package.json</code> is large but these two lines may be relevant:</p>
  <pre><code>...
    &quot;devDependencies&quot;: {
      ...
      &quot;sass&quot;: &quot;^1.46.0&quot;,
      &quot;sass-loader&quot;: &quot;10.1.1&quot;,
  ...
  </code></pre>
  <p>)</p>
  <pre><code>$ npm install
  
  npm ERR! code 1
  npm ERR! git dep preparation failed
  npm ERR! command /usr/bin/node /usr/lib/node_modules/npm/bin/npm-cli.js install --force --cache=/home/username/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run
  npm ERR! npm WARN using --force Recommended protections disabled.
  npm ERR! npm WARN old lockfile 
  npm ERR! npm WARN old lockfile The package-lock.json file was created with an old version of npm,
  npm ERR! npm WARN old lockfile so supplemental metadata must be fetched from the registry.
  npm ERR! npm WARN old lockfile 
  npm ERR! npm WARN old lockfile This is a one-time fix-up, please be patient...
  npm ERR! npm WARN old lockfile 
  npm ERR! npm WARN deprecated &lt;many many warnings...&gt;
  npm ERR! npm ERR! code 1
  npm ERR! npm ERR! path /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-sass
  npm ERR! npm ERR! command failed
  npm ERR! npm ERR! command sh -c node scripts/build.js
  npm ERR! npm ERR! Building: /usr/bin/node /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
  npm ERR! npm ERR! gyp info it worked if it ends with ok
  npm ERR! npm ERR! gyp verb cli [
  npm ERR! npm ERR! gyp verb cli   '/usr/bin/node',
  npm ERR! npm ERR! gyp verb cli   '/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js',
  npm ERR! npm ERR! gyp verb cli   'rebuild',
  npm ERR! npm ERR! gyp verb cli   '--verbose',
  npm ERR! npm ERR! gyp verb cli   '--libsass_ext=',
  npm ERR! npm ERR! gyp verb cli   '--libsass_cflags=',
  npm ERR! npm ERR! gyp verb cli   '--libsass_ldflags=',
  npm ERR! npm ERR! gyp verb cli   '--libsass_library='
  npm ERR! npm ERR! gyp verb cli ]
  npm ERR! npm ERR! gyp info using node-gyp@3.8.0
  npm ERR! npm ERR! gyp info using node@16.14.0 | linux | x64
  npm ERR! npm ERR! gyp verb command rebuild []
  npm ERR! npm ERR! gyp verb command clean []
  npm ERR! npm ERR! gyp verb clean removing &quot;build&quot; directory
  npm ERR! npm ERR! gyp verb command configure []
  npm ERR! npm ERR! gyp verb check python checking for Python executable &quot;python2&quot; in the PATH
  npm ERR! npm ERR! gyp verb `which` failed Error: not found: python2
  npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:13:12)
  npm ERR! npm ERR! gyp verb `which` failed     at F (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:68:19)
  npm ERR! npm ERR! gyp verb `which` failed     at E (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:80:29)
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:89:16
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/index.js:42:5
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/mode.js:8:5
  npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21)
  npm ERR! npm ERR! gyp verb `which` failed  python2 Error: not found: python2
  npm ERR! npm ERR! gyp verb `which` failed     at getNotFoundError (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:13:12)
  npm ERR! npm ERR! gyp verb `which` failed     at F (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:68:19)
  npm ERR! npm ERR! gyp verb `which` failed     at E (/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:80:29)
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/node_modules/which/which.js:89:16
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/index.js:42:5
  npm ERR! npm ERR! gyp verb `which` failed     at /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/isexe/mode.js:8:5
  npm ERR! npm ERR! gyp verb `which` failed     at FSReqCallback.oncomplete (node:fs:198:21) {
  npm ERR! npm ERR! gyp verb `which` failed   code: 'ENOENT'
  npm ERR! npm ERR! gyp verb `which` failed }
  npm ERR! npm ERR! gyp verb check python checking for Python executable &quot;python&quot; in the PATH
  npm ERR! npm ERR! gyp verb `which` succeeded python /usr/bin/python
  npm ERR! npm ERR! gyp ERR! configure error 
  npm ERR! npm ERR! gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print &quot;%s.%s.%s&quot; % sys.version_info[:3];
  npm ERR! npm ERR! gyp ERR! stack   File &quot;&lt;string&gt;&quot;, line 1
  npm ERR! npm ERR! gyp ERR! stack     import sys; print &quot;%s.%s.%s&quot; % sys.version_info[:3];
  npm ERR! npm ERR! gyp ERR! stack                       ^
  npm ERR! npm ERR! gyp ERR! stack SyntaxError: invalid syntax
  npm ERR! npm ERR! gyp ERR! stack 
  npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:399:12)
  npm ERR! npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
  npm ERR! npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1092:16)
  npm ERR! npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
  npm ERR! npm ERR! gyp ERR! System Linux 5.15.0-18-generic
  npm ERR! npm ERR! gyp ERR! command &quot;/usr/bin/node&quot; &quot;/home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-gyp/bin/node-gyp.js&quot; &quot;rebuild&quot; &quot;--verbose&quot; &quot;--libsass_ext=&quot; &quot;--libsass_cflags=&quot; &quot;--libsass_ldflags=&quot; &quot;--libsass_library=&quot;
  npm ERR! npm ERR! gyp ERR! cwd /home/username/.npm/_cacache/tmp/git-clonebeOztg/node_modules/node-sass
  npm ERR! npm ERR! gyp ERR! node -v v16.14.0
  npm ERR! npm ERR! gyp ERR! node-gyp -v v3.8.0
  npm ERR! npm ERR! gyp ERR! not ok 
  npm ERR! npm ERR! Build failed with error code: 1
  </code></pre>
  <p>Especially, this line is not a valid Python3.x synthax: <code>import sys; print &quot;%s.%s.%s&quot; % sys.version_info[:3];</code> so even <em>faking</em> a symlink called 'python' or 'python2' which points to -&gt; '/usr/bin/python3.9' on the system doesn't help, naturally.</p>
  <p><code>npm cache clean --force</code> doesn't help either.</p>
  <p>System info:</p>
  <pre><code>$ npm --version
  8.3.1
  $ node --version
  v16.14.0
  $ uname -mor
  5.15.0-18-generic x86_64 GNU/Linux
  </code></pre>
  <p>Any hints on what I can do to fix this error?</p>