web3@1.0.0-beta.26 使用 Yarn 安装失败

web3@1.0.0-beta.26 Install Fails with Yarn

以下安装失败:

$ sudo yarn add -P web3@1.0.0-beta.26

这是错误:

gyp ERR! configure error 
gyp ERR! stack Error: Python executable "/anaconda3/bin/python" is v3.6.4, which is not supported by gyp.
gyp ERR! stack You can pass the --python switch to point to Python >= v2.5.0 & < 3.0.0.

如果我使用 'npm' 作为包管理器,以下命令可以解决问题:

$ sudo npm install --save web3@1.0.0-beta.26 --python=pyhon2.7

但是,我使用 'create-react-app' 引导我的项目,默认使用 'yarn' 作为包管理器。

那么,如错误消息中所述,使用 'yarn' 切换 python 版本的语法是什么。我已经猜测了几种变化但无济于事。而且,我没有找到适合这种情况的解决方案。

尝试将 python 版本设置为环境变量。

npm config --global set python /usr/bin/python2.7

您可以在 this issue

中阅读更多相关信息