Node.js:由于node-sass和node-gyp,Python未找到异常

ovfsdjhp  于 2022-09-21  发布在  Node.js
关注(0)|答案(30)|浏览(209)

突然,在我的一个Jenkins环境中,构建开始失败,而在本地机器上,它似乎工作得很好,因为我已经安装了Python,

当我通过访问this研究node-gyp时,我发现问题出在内部依赖上,即node-sass v3.8.0中的node-gyp v3.5.0,找到了需要安装Python的前提条件。

所以我的问题是,我可以安装什么版本的node-sass来绕过这一点,或者有没有更好的解决方案,因为我的构建直到今天早上还在相同的环境中运行得很好。

节点v5.10.1

错误日志

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
gyp verb `which` failed     at getNotFoundError (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:13:12)
gyp verb `which` failed     at F (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:68:19)
gyp verb `which` failed     at E (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:80:29)
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:89:16
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesisexeindex.js:44:5
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesisexewindows.js:29:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:82:15)
gyp verb `which` failed  python2 { [Error: not found: python2] code: 'ENOENT' }
gyp verb check python checking for Python executable "python" in the PATH
gyp verb `which` failed Error: not found: python
gyp verb `which` failed     at getNotFoundError (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:13:12)
gyp verb `which` failed     at F (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:68:19)
gyp verb `which` failed     at E (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:80:29)
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_moduleswhichwhich.js:89:16
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesisexeindex.js:44:5
gyp verb `which` failed     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesisexewindows.js:29:5
gyp verb `which` failed     at FSReqWrap.oncomplete (fs.js:82:15)
gyp verb `which` failed  python { [Error: not found: python] code: 'ENOENT' }
gyp verb could not find "python". checking python launcher 
gyp verb could not find "python". guessing location 
gyp verb ensuring that file exists: C:Python27python.exe
gyp ERR! configure error 
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack     at Object.failNoPython (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesnode-gyplibconfigure.js:454:19)
gyp ERR! stack     at Object.<anonymous> (C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesnode-gyplibconfigure.js:480:16)
gyp ERR! stack     at C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesgraceful-fspolyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:82:15)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-gyp\bin\node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd C:Program Files (x86)JenkinsjobsNdbSite-hot-fix-Manual-PreBuildworkspacesrcNdbSite.UInode_modulesnode-sass
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok 
Build failed

如有任何想法,我们将不胜感激,谢谢。

fcy6dtqo

fcy6dtqo1#

最近,我在Windows上遇到了这种情况。我通过使用具有管理员权限的PowerShell执行以下步骤来修复它:

1.删除node_modules文件夹
1.以管理权限运行npm install --global windows-build-tools。(在我的情况下,需要重新启动-并且在没有询问的情况下重新启动!)
1.使用npm install重新安装节点模块或节点会话

kknvjkwl

kknvjkwl2#

该错误消息意味着它找不到您的python可执行文件或二进制文件。

在许多情况下,它安装在c:\python27。如果它还没有安装,你可以用npm install --global windows-build-tools安装它,只有在还没有安装的情况下才能工作。

将其添加到环境变量并不总是有效的。更好的替代方法是在NPM配置中设置它。

npm config set python "C:Python27python.exe"

i86rm4rw

i86rm4rw3#

您需要按照以下步骤修复该错误:

1: DELETE node_modules
    2: npm install node-sass@<version-as-per-below-table>
    3. npm install
  • 每个node-sass版本对应一个具体的Node.js版本。*

以下是支持的最低和最高支持的node-sass版本(Check updates to below table here)的快速指南:

| NodeJS  | Supported node-sass version | Node Module |
|---------|-----------------------------|-------------|
| Node 16 | 6.0+                        | 93          |
| Node 15 | 5.0+                        | 88          |
| Node 14 | 4.14+                       | 83          |
| Node 13 | 4.13+, <5.0                 | 79          |
| Node 12 | 4.12+                       | 72          |
| Node 11 | 4.10+, <5.0                 | 67          |
| Node 10 | 4.9+, <6.0                  | 64          |
| Node 8  | 4.5.3+, <5.0                | 57          |
| Node <8 | <5.0                        | <57         |
b0zn9rqh

b0zn9rqh4#

我的机器是Windows 10,在尝试使用node-sass包编译sass时也遇到了类似的问题。我的节点版本是v10.16.3,NPM版本是6.9.0

我解决问题的方式:

1.首先删除package-lock.json文件和node_modules/文件夹。
1.以管理员身份打开Windows PowerShell。
1.运行命令npm i -g node-sass
1.之后,转到项目文件夹并运行npm install
1.最后运行sass编译脚本,在我的例子中,它是npm run build:css

它成功了!!

6ss1mwsb

6ss1mwsb5#

在安装时,node-sass会尝试为您的平台下载二进制文件。Node 5受3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0支持如果您的Jenkins无法下载预构建的二进制文件,那么您需要遵循Node-gyp自述文件上的平台要求(Python2、VS或MSBuild,...)如果可能,我建议您至少将Node更新到6,因为Node不再支持5。如果要升级到8,则需要将node-sass更新到4.5.3

omqzjyyz

omqzjyyz6#

两种选择(2021年12月):

  • 1-您不能升级“node-sass”包!

  • 安装Python2并修改其.exe文件名。

  • 修复PATH环境变量记录顺序(详细信息如下)。

  • 2-更新node-sass包。

前提条件

已在Windows 10上将Node.js更新为最新版本(v16.13.1)。
您在项目的文件夹中运行yarn installnpm install,并收到错误(如下所示)。

选项1.安装Python-2并修复PATH环境

See MSI installer

安装后

  • 注意!*如果在x64上出现以下错误,请尝试将最新的Node.js从x64重新安装到x86。(但使用x86时,您也可能收到内存限制错误。)
Error: Node Sass does not yet support your current environment: Windows 64-bit with Unsupported runtime (93)

重新排序PATH环境变量中的Python记录

PYTHON%3记录必须高于PYTHON%2记录!

python.exe复制到python2.exe

选项2.升级node-sass套餐

覆盖package.json文件

修改package.json并在项目文件夹上运行yarn installnpm install
其他文件将自动更新。

在之前

更新后:

或者使用Yarn或NPM CLI来执行相同的操作,但它可能会显著更改您的.lock文件。

更新后,您可能会意识到还需要更新sass-loaderwebpack等。

您可能遇到的错误(仅供参考)

gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2

gyp ERR! stack Error: Command failed: C:Python310python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack   File "<string>", line 1
gyp ERR! stack     import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
3qpi33ja

3qpi33ja7#

node-gyp需要旧Python2-link

如果您尚未安装,请查看有关安装WINDOWS-Build-Tools的其他答案。

如果您和我一样,同时安装了旧版本和新版本,那么node-gyp很可能会尝试使用Python3。这会导致以下SyntaxError: invalid syntax错误。

我找到了一篇关于安装了两个版本的Python的文章。他们建议将Python2.*可执行文件重命名为python2.exe-link

因此,看起来node-gyp希望找到已重命名的旧的Python2可执行文件。因此出现以下错误消息:

...
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
...

一旦我将C:\Python27\python.exe重命名为C:\Python27\python2.exe,它就可以正常工作了。

当然,C:\Python27\C:\Python39\都必须在PATH变量中。并且不需要在NPM配置中设置旧的Python版本。您的默认Python仍将是新的。

y3bcpkx1

y3bcpkx18#

我不得不:

Delete node_modules
Uninstall/reinstall node
npm install node-sass@4.12.0

根据据说正在与正确的节点一起工作的版本,在强制它使用正确的sass版本后,它运行得很好。

NodeJS  Minimum node-sass version   Node Module
Node 12 4.12+   72
Node 11 4.10+   67
Node 10 4.9+    64
Node 8  4.5.3+  57

还有许多其他错误似乎是由错误的sass版本定义引起的。

s8vozzvw

s8vozzvw9#

自2020年10月26日起,node-sass已过时

无需安装旧版本的Python,只需迁移到dart.sass即可

对于我的ReactJS项目(NPM),以下步骤对我有效:

1.从工程中删除NODE_MODULES
1.在Package.json中,移除该依赖:

"dependencies": {
    …,
    "node-sass": "^3.0.0",
    …
}

1.npm install --save-dev sass
1.npm install
1.现在尝试使用npm start运行您的项目
1.如果收到错误消息,如要导入Sass文件,首先需要安装node-sass,请按照here的说明运行以下命令:
npm install node-sass@npm:sass

如果您使用的是Yarn,请执行相同的命令,但在最后一步中,请执行以下操作,如here所述:
yarn remove node-sass
yarn add sass

jfewjypa

jfewjypa10#

**我的答案可能不适用于所有人。**节点版本:v10.16.0 npm:6.9.0

我在使用node-sassnode-sass-middleware时遇到了很多问题。它们是有趣的包,因为它们被广泛使用(每周有数百万的下载量),但它们的巨无霸显示出有限的依赖性和覆盖范围。我正在更新我一直在使用的一个较旧的平台。

我最终不得不做的是:

**1)**手动Delete node_modules

**2)**手动Delete package-lock.json

3)sudo npm install node-sass --unsafe-perm=true --allow-root

4)sudo npm install node-sass-middleware --unsafe-perm=true --allow-root

我得到了以下帮助,谢谢!

Pre-built binaries not found for grpc@1.10.1 and node@10.9.0

Error: EACCES: permission denied when trying to install ESLint using npm

vawmfj5a

vawmfj5a11#

我在Windows11机器上,为了修复它,我自己下载了python27,使用这个链接:https://www.python.org/download/releases/2.7/

在安装之后,我运行了以下命令:

npm config set python c:python27python.exe
eqfvzcg8

eqfvzcg812#

转到Package.json并更改

"node-sass": "4.14.1",

使用

"node-sass": "^7.0.1",

在我可以运行NPM安装后,它对我起作用

换句话说,您需要使用支持最新版本的最新包。

**注意:**Node Saas 7.0.1兼容React脚本:5.0.0如果您的Package.json有React脚本:4.0.0,则改为

"react-scripts": "5.0.0",
ffvjumwh

ffvjumwh13#

这是两年前的事了,但他们都没帮我。

我卸载了NodeJS v12.8.1(当前),并安装了全新的v10.16.3(LTS),我的ng build --prod工作正常。

iswrvxsc

iswrvxsc14#

嘿,我按照以下步骤解决了这个错误

  • 先卸载最新版本python3.8.6*
  • 然后我安装了Python2.7.1**(任何Python2版本都可以,但不会太老,推荐使用)
  • 然后我将c:\python27添加到环境变量
  • 我的操作系统是WINDOWS,所以我遵循了这个link
  • 它奏效了
abithluo

abithluo15#

我有node 15.x.x"node-sass": "^4.11.0"。我在node-sass的发行说明中看到,与node-sass 4.11.0兼容的节点最高版本是11,所以我卸载了node并重新安装了11.15.0版本(我正在使用Windows)。检查node-sass releases(this is what you should see in the node-sass releases.)

希望这对我的英语有帮助和抱歉:)

相关问题