在Windows的Truffle5/Web3中遇到Python错误时,可以尝试使用windows-build-tools来解决

如果在Windows上使用npm安装Web3 1.0或Truffle 5,经常会遇到无法顺利进行的问题。

我想可能会出现这样的错误。错误提示为缺少Python可执行文件。

$ npm i web3

> tiny-secp256k1@1.0.1 install \node_modules\tiny-secp256k1
> node-gyp rebuild


\node_modules\tiny-secp256k1>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
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 PythonFinder.failNoPython (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:484:19)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:509:16)
gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
gyp ERR! stack     at FSReqWrap.oncomplete (fs.js:153:21)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd \node_modules\tiny-secp256k1

在这种情况下,你可以尝试使用Windows构建工具来解决问题。

以管理员权限启动PowerShell,并执行以下命令。

npm install --global windows-build-tools

除了Python 2.7之外,还会安装各种其他东西。

如果使用web3 0.20.6或truffle 4.1.15,就不会遇到这种错误。

广告
将在 10 秒后关闭
bannerAds