![在 Ubuntu 16.04 上安装 ethereumjs 时出现“ImportError: 没有名为 pkg_resources 的模块”。我该如何修复这个问题?](https://linux22.com/image/1148229/%E5%9C%A8%20Ubuntu%2016.04%20%E4%B8%8A%E5%AE%89%E8%A3%85%20ethereumjs%20%E6%97%B6%E5%87%BA%E7%8E%B0%E2%80%9CImportError%3A%20%E6%B2%A1%E6%9C%89%E5%90%8D%E4%B8%BA%20pkg_resources%20%E7%9A%84%E6%A8%A1%E5%9D%97%E2%80%9D%E3%80%82%E6%88%91%E8%AF%A5%E5%A6%82%E4%BD%95%E4%BF%AE%E5%A4%8D%E8%BF%99%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9F.png)
我正在跟进这教程:为众筹创建以太坊智能合约。我使用的是 Ubuntu 16.04,这个问题困扰了我好几个小时,却一直没能解决。我查了一下“无法获取错误”,有些错误很类似,但提出的解决方案都不起作用。
当我输入:
npm install -g ethereumjs-testrpc
进入终端,我收到以下错误:
ImportError: No module named pkg_resources
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:354:16)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Linux 3.16.0-77-generic
gyp ERR! command "/usr/bin/nodejs" "/usr/bin/node-gyp" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/ethereumjs-testrpc/node_modules/scrypt
gyp ERR! node -v v4.2.6
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
/usr/local/lib
└── (empty)
npm ERR! Linux 3.16.0-77-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "ethereumjs-testrpc"
npm ERR! node v4.2.6
npm ERR! npm v3.5.2
npm ERR! code ELIFECYCLE
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the scrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs scrypt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls scrypt
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/fappycow/npm-debug.log
npm ERR! code 1
我知道如何修复这些问题吗?
答案1
您的 Node.js 版本太旧。从错误日志中可以看出,您的 Node.js 版本是 4.2.6,但ethereum-testrpc
“至少需要 Node 6.9.1 才能运行”,如https://github.com/ethereumjs/testrpc。要安装 Node.js >= 6.x,请参阅 Ubuntu 的说明https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions,我将其逐字复制如下:
Node.js 6.x
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - sudo apt-get install -y nodejs
Node.js 8.x
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs