npm 安装 npm 错误! gyp 动词 `which` 失败错误:未找到:python2

发布于 2025-01-09 18:22:32 字数 6988 浏览 1 评论 0原文

在 Ubuntu 21.10 上,实际上没有安装 Python2.x,在大型项目上执行“npm install”时,我遇到以下错误(package.json 很大,但这两行可能是相关

...
  "devDependencies": {
    ...
    "sass": "^1.46.0",
    "sass-loader": "10.1.1",
...

:)

$ 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 <many many warnings...>
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 [email protected]
npm ERR! npm ERR! gyp info using [email protected] | 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 "build" directory
npm ERR! npm ERR! gyp verb command configure []
npm ERR! npm ERR! gyp verb check python checking for Python executable "python2" 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 "python" 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 "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % 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 "/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 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

特别是,这一行不是有效的 Python3.x 合成: import sys; print "%s.%s.%s" % sys.version_info[:3]; 因此,即使伪造一个名为“python”或“python2”的符号链接指向 ->系统上的“/usr/bin/python3.9”自然没有帮助。

npm cache clean --force 也没有帮助。

系统信息:

$ npm --version
8.3.1
$ node --version
v16.14.0
$ uname -mor
5.15.0-18-generic x86_64 GNU/Linux

有关如何修复此错误的任何提示?

On Ubuntu 21.10, where Python2.x is actually not installed, I'm facing the following error when executing "npm install" on a large project (the package.json is large but these two lines may be relevant:

...
  "devDependencies": {
    ...
    "sass": "^1.46.0",
    "sass-loader": "10.1.1",
...

)

$ 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 <many many warnings...>
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 [email protected]
npm ERR! npm ERR! gyp info using [email protected] | 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 "build" directory
npm ERR! npm ERR! gyp verb command configure []
npm ERR! npm ERR! gyp verb check python checking for Python executable "python2" 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 "python" 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 "%s.%s.%s" % sys.version_info[:3];
npm ERR! npm ERR! gyp ERR! stack   File "<string>", line 1
npm ERR! npm ERR! gyp ERR! stack     import sys; print "%s.%s.%s" % 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 "/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 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

Especially, this line is not a valid Python3.x synthax: import sys; print "%s.%s.%s" % sys.version_info[:3]; so even faking a symlink called 'python' or 'python2' which points to -> '/usr/bin/python3.9' on the system doesn't help, naturally.

npm cache clean --force doesn't help either.

System info:

$ npm --version
8.3.1
$ node --version
v16.14.0
$ uname -mor
5.15.0-18-generic x86_64 GNU/Linux

Any hints on what I can do to fix this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

糖粟与秋泊 2025-01-16 18:22:32

我遇到了类似的问题并在没有安装 Payton 的情况下解决了它。也许这种方式可以帮助你。

sass-loader 要求您安装 Dart SassNode-Sass
我使用了 Node-Sass,并在启动 npm install 之前手动安装了它。

因此,我的步骤是:

  1. 删除node_modules
  2. 删除package-lock.json(可选)
  3. npm install node-sass@
  4. npm install

考虑到几点:

  • node-sass 版本必须与 Node.js 版本相对应。以下是快速指南,了解支持的最低和最高版本节点 sass:

    <表类=“s-表”>
    <标题>

    NodeJS
    支持的node-sass版本
    节点模块


    <正文>

    节点 16
    6.0+
    93

    节点 15
    5.0+
    88

    节点 14
    4.14+
    83

    节点 13
    4.13+,<5.0
    79

    节点 12
    4.12+
    72

    节点11
    4.10+,<5.0
    67

    节点 10
    4.9+,<6.0
    64

    节点8
    4.5.3+,<5.0
    57

    节点<8
    <5.0
    <57

  • 当前 Node Sass 是已弃用,因此我建议使用 Dart Sass

值得一提的是,快速更改 NodeJS 版本的简单方法是使用 nvm

I faced with similar issue and solve it without installing Payton at all. Probably this way help you.

sass-loader requires you to install either Dart Sass or Node-Sass.
I used Node-Sass, and installed it manually before launching npm install.

Thus my steps:

  1. remove node_modules
  2. remove package-lock.json (optionally)
  3. npm install node-sass@
  4. npm install

Take into account a couple of points:

  • node-sass version have to be corresponded with Node.js version. Below is a quick guide for minimum and maximum supported versions of node-sass:

    NodeJSSupported node-sass versionNode Module
    Node 166.0+93
    Node 155.0+88
    Node 144.14+83
    Node 134.13+, <5.079
    Node 124.12+72
    Node 114.10+, <5.067
    Node 104.9+, <6.064
    Node 84.5.3+, <5.057
    Node <8<5.0<57
  • Currently Node Sass is deprecated so I'd recommend to use Dart Sass.

And it worths to be mentioned that easy way to fast changing version of nodejs is use nvm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文