安装 composer-cli 时出错

errors installing composer-cli

我无法正确安装 composer-cli。我试过用自制软件和其他方法卸载节点和 npm。我收到有关 python 安装的错误。所以我继续安装 python2.7 并指示 npm 使用它。这似乎解决了那个特定的错误,但随后出现了其他错误。如果有人对此问题有经验,我将不胜感激。谢谢!

日志文件:

16859 verbose argv "/Users/jcole/.nvm/versions/node/v8.12.0/bin/node" 
"/Users/jcole/.nvm/versions/node/v8.12.0/bin/npm" "install" "-g" "composer-cli"
16860 verbose node v8.12.0
16861 verbose npm  v6.4.1
16862 error code ELIFECYCLE
16863 error errno 1
16864 error node-report@2.2.1 install: `node-gyp rebuild`
16864 error Exit status 1
16865 error Failed at the node-report@2.2.1 install script.
16865 error This is probably not a problem with npm. There is likely additional logging output above.
16866 verbose exit [ 1, true ]

终端:

[~]$ npm install -g composer-cli
/Users/jcole/.nvm/versions/node/v8.12.0/bin/composer -> /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/cli.js

> dtrace-provider@0.8.7 install /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/local/bin/python -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: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:276:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:336:11)
gyp ERR! stack     at emitOne (events.js:116:13)
gyp ERR! stack     at Socket.emit (events.js:211:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:561:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/jcole/.nvm/versions/node/v8.12.0/bin/node" "/Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/dtrace-provider
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> fsevents@1.2.4 install /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/fsevents
> node install

[fsevents] Success: "/Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

> node-report@2.2.1 install /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/node-report
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /usr/local/bin/python -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: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:276:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:336:11)
gyp ERR! stack     at emitOne (events.js:116:13)
gyp ERR! stack     at Socket.emit (events.js:211:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:561:12)
gyp ERR! System Darwin 17.7.0
gyp ERR! command "/Users/jcole/.nvm/versions/node/v8.12.0/bin/node" "/Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jcole/.nvm/versions/node/v8.12.0/lib/node_modules/composer-cli/node_modules/node-report
gyp ERR! node -v v8.12.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-report@2.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-report@2.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jcole/.npm/_logs/2018-09-18T01_49_06_082Z-debug.log
[~]$ 

看起来它仍在使用 python3 安装。您可以尝试完全删除 python3 或从 shell 中禁用吗?

这是基于错误的结果:

$ python -c 'import sys; print "%s.%s.%s" % sys.version_info[:3];'
2.7.15
$ python3 -c 'import sys; print "%s.%s.%s" % sys.version_info[:3];'
  File "<string>", line 1
    import sys; print "%s.%s.%s" % sys.version_info[:3];
                               ^
SyntaxError: invalid syntax

OSX (Darwin 17.7.0) 附带 python 2.7 并且 npm 使用的许多底层脚本期望并使用 "Old Style" 字符串格式与 " %”。如果您已从 2000 年代后期升级到 Python 3+.

,则此方法无效

每次(重新)安装具有此问题的组件时,此问题都会不断弹出。反复卸载和重新安装 python 非常令人沮丧。

解决方法:暂时将 OSX 的原始 python 可执行文件放在 $PATH 的前面,运行 你 npm install。它通常在 /usr/bin 所以试试:

$ GOODPATH=$PATH
$ export PATH=/usr/bin:$PATH
$ python --version
Python 2.7.10
npm install ....
$ export PATH=$GOODPATH
$ python --version
Python 3.7.2

同样的问题发生在 运行 npm install -g composer-cli on macOS Mojave(10.14.3) 节点版本:v8.15.1, nvm 版本:0.33.0, npm 版本:6.4.1

终端:

MacBook-Air:~ shantanu$ npm install -g composer-cli@0.20
/Users/shantanu/.nvm/versions/node/v8.15.1/bin/composer -> /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/cli.js

> dtrace-provider@0.8.7 install /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/dtrace-provider
> node-gyp rebuild || node suppress-error.js

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /anaconda3/bin/python -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: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:281:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Socket.stream.socket.on (internal/child_process.js:336:11)
gyp ERR! stack     at emitOne (events.js:116:13)
gyp ERR! stack     at Socket.emit (events.js:211:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:561:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/Users/shantanu/.nvm/versions/node/v8.15.1/bin/node" "/Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/dtrace-provider
gyp ERR! node -v v8.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 

> fsevents@1.2.7 install /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/fsevents
> node install

node-pre-gyp WARN Using request for node-pre-gyp https download 
[fsevents] Success: "/Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node" is installed via remote

> node-report@2.2.1 install /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/node-report
> node-gyp rebuild

gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /anaconda3/bin/python -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: invalid syntax
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:281:12)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/Users/shantanu/.nvm/versions/node/v8.15.1/bin/node" "/Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/shantanu/.nvm/versions/node/v8.15.1/lib/node_modules/composer-cli/node_modules/node-report
gyp ERR! node -v v8.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-report@2.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-report@2.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/shantanu/.npm/_logs/2019-03-16T10_22_33_184Z-debug.log

发生错误,因为它正在使用 python3 安装。卸载 python3 不是一个好的选择所以我暂时将 python 默认路径更改为 OSX 的原始 pyhton 路径

  $ GOODPATH=$PATH
    $ export PATH=/usr/bin:$PATH
    $ python --version
    Python 2.7.10

然后使用https://hyperledger.github.io/composer/latest/installing/development-tools.html

中提到的命令安装composer-cli

并且在成功安装 composer-cli 后更改了默认 python 路径,因为它是以前的。

$ export PATH=$GOODPATH
$ python --version
Python 3.6.5 :: Anaconda, Inc.

我通过 =>

在我的 Ubuntu 18.04 机器上解决了同样的问题

正在 https://hyperledger.github.io/composer/latest/installing/installing-prereqs.html

安装先决条件

这表示->

curl -O https://hyperledger.github.io/composer/latest/prereqs-ubuntu.sh

然后 chmod u+x 先决条件-ubuntu.sh 最后=>

./prereqs-ubuntu.sh

然后重新启动终端并尝试安装 =>

npm install -g composer-cli@0.20

没有 su 或 sudo。我希望这会有所帮助:):)

您可能还想尝试使用 --unsafe-perm 安装...

对我有用...