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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45801457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:26:50  来源:igfitidea点击:

Node.js: Python not found exception due to node-sass and node-gyp

node.jsnode-gypnode-sass

提问by Vipul Panth

Suddenly in one of my jenkins environment build has started failing, while in local machine it seems to be working fine as i have python installed,

突然在我的一个 jenkins 环境中构建开始失败,而在本地机器上它似乎工作正常,因为我安装了 python,

From the logs i was able to detect that the problem is with internal dependency that is node-gyp v3.5.0from node-sass v3.8.0when i researched by visiting thisabout node-gyp and found the prerequisite that Python needs to be installed.

从日志中我能检测到的问题是内部的依赖是节点GYP V3.5.0节点萨斯v3.8.0当我访问研究,约节点GYP,发现先决条件的Python需要安装.

So my question is that what version of node-sass can i install to bypass this or is there a better solution as my build was running fine till this morning on the same environment.

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

Node v5.10.1

节点 v5.10.1

ERROR LOG

错误日志

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)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\index.js:44:5
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\windows.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)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:13:12)
gyp verb `which` failed     at F (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:68:19)
gyp verb `which` failed     at E (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:80:29)
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\which\which.js:89:16
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\index.js:44:5
gyp verb `which` failed     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\isexe\windows.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:\Python27\python.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)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-gyp\lib\configure.js:454:19)
gyp ERR! stack     at Object.<anonymous> (C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-gyp\lib\configure.js:480:16)
gyp ERR! stack     at C:\Program Files (x86)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\graceful-fs\polyfills.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)\Jenkins\jobs\NdbSite-hot-fix-Manual-PreBuild\workspace\src\NdbSite.UI\node_modules\node-sass
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.5.0
gyp ERR! not ok 
Build failed

Any thoughts are much appreciated, Thanks.

任何想法都非常感谢,谢谢。

采纳答案by nschonni

Node-sass tries to download the binary for you platform when installing. Node 5 is supported by 3.8 https://github.com/sass/node-sass/releases/tag/v3.8.0If your Jenkins can't download the prebuilt binary, then you need to follow the platform requirements on Node-gyp README (Python2, VS or MSBuild, ...) If possible I'd suggest updating your Node to at least 6 since 5 isn't supported by Node anymore. If you want to upgrade to 8, you'll need to update node-sass to 4.5.3

安装时,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

回答by Shezan Kazi

so this happened to me on windows recently. I fix it by following the following steps using a PowerShell with admin privileges:

所以这最近发生在我身上。我使用具有管理员权限的 PowerShell 按照以下步骤修复它:

  1. delete node_modulesfolder
  2. running npm install --global windows-build-tools
  3. reinstalling node modules or node-sass with npm install
  1. 删除node_modules文件夹
  2. 跑步 npm install --global windows-build-tools
  3. 重新安装节点模块或节点sass npm install

回答by Stephen Himes

I had to:

我不得不:

Delete node_modules
Uninstall/reinstall node
npm install [email protected]

worked fine after forcing it to the right sass version, according to the version said to be working with the right node.

根据据说与正确节点一起工作的版本,在将其强制为正确的 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

There was lots of other errors that seemed to be caused by the wrong sass version defined.

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

回答by Bruno Miquelin

This is 2 years old, but none of them helped me.

这是2岁,但他们都没有帮助我。

I uninstalled my NodeJS v12.8.1 (Current) and installed a brand new v10.16.3 (LTS) and my ng build --prodworked.

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

回答by Fatema T. Zuhora

My machine is Windows 10, I've faced similar problems while tried to compile SASSusing node-sasspackage. My node version is v10.16.3and npm version is 6.9.0

我的机器是Windows 10,我在尝试使用package.json编译SASS时遇到了类似的问题node-sass。我的 node 版本是v10.16.3,npm 版本是6.9.0

The way that I resolved the problem:

我解决问题的方法:

  1. At first delete package-lock.jsonfile and node_modules/folder.
  2. Open Windows PowerShell as Administrator.
  3. Run the command npm i -g node-sass.
  4. After that, go to the project folder and run npm install
  5. And finally, run the SASS compiling script, in my case, it is npm run build:css
  1. 首先删除package-lock.json文件和node_modules/文件夹。
  2. 以管理员身份打开 Windows PowerShell。
  3. 运行命令npm i -g node-sass
  4. 之后,转到项目文件夹并运行 npm install
  5. 最后,运行SASS 编译脚本,就我而言,它是npm run build:css

And it works!!

它有效!!

回答by maudulus

My answer might not apply to everyone.Node version: v10.16.0NPM: 6.9.0

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

I was having a lot of trouble using node-sassand node-sass-middleware. They are interesting packages because they are widely used (millions of downloads weekly), but their githubs show a limited dependencies and coverage. I was updating an older platform I'd been working on.

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

What I ended up having to do was:

我最终不得不做的是:

1)Manually Delete node_modules

1)手动Delete node_modules

2)Manually Delete package-lock.json

2)手动Delete package-lock.json

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

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

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

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

I had the following help, thanks!

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

Pre-built binaries not found for [email protected] and [email protected]

未找到 [email protected][email protected] 的预构建二进制文件

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

错误:EACCES:尝试使用 npm 安装 ESLint 时权限被拒绝

回答by davyCode

had the same issue lost hours trying to install different version of python on my PC. Simply Upgrade node to the latest version v8.11.2 and npm 5.6.0, then after install [email protected] and you'll be fine.

尝试在我的 PC 上安装不同版本的 python 时,同样的问题浪费了数小时。只需将 node 升级到最新版本 v8.11.2 和 npm 5.6.0,然后安装 [email protected] 就可以了。

回答by MwamiTovi

After looking at all the answers, i notice this solution might be very helpful. It explains how to configure "npm" to find your installed python versionwhile installing node-sass. Remember, node-sass requires node-gyp (an npm build-tool) which looks for your python path. Or just install python, and follow the same solution given (in the link). Thanks.

查看所有答案后,我注意到此解决方案可能非常有帮助。它解释了如何在安装 node-sass 时配置“npm”以查找已安装的 python 版本。请记住,node-sass 需要 node-gyp(一个 npm 构建工具)来查找您的 python 路径。或者只是安装 python,并按照给出的相同解决方案(在链接中)。谢谢。