安装npm组件时出现Python语法错误

2024-10-03 21:24:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试通过npm安装以下vue组件:

https://github.com/xwpongithub/vue-range-slider

我安装它的目的是:

npm install vue-range-component --save

但是,我在控制台中遇到以下错误:

> fsevents@1.2.11 install /Users/jovan/Desktop/work/projects/topgraphs/node_modules/fsevents
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/jovan/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:294:12)
gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:430:11)
gyp ERR! stack     at Socket.emit (events.js:200:13)
gyp ERR! stack     at Pipe.<anonymous> (net.js:586:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/usr/local/Cellar/node/12.3.1/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jovan/Desktop/work/projects/topgraphs/node_modules/fsevents
gyp ERR! node -v v12.3.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules/fsevents):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ vue-range-component@1.0.3

显然,该组件已经安装,但是Python中存在某种语法错误?在互联网上搜索解决方案时,我只找到了一些对不同Python版本的引用,但在上面的整个错误输出中没有提到版本。我正在使用Python 3.7


Tags: installmodulesnodenpmstacksysjsrange
2条回答

是的,给出的Python代码仅对python3之前的Python版本有效

import sys; print "%s.%s.%s" % sys.version_info[:3];

在python3中print语句是一个函数,因此不能省略括号。应更新包以使用:

import sys; print("%s.%s.%s" % sys.version_info[:3]);

。。相反

语法

print "string"

在Python 3+中无效

您有Python3,但是库使用Python2.7,所以请安装Python2.7

相关问题 更多 >