在 CentOS 8 returns 上使用 python 编译错误

Compiling with python on CentOS 8 returns errors

我已经安装了最新的节点、npm 和 python 版本,但是当我尝试安装 leveldown(使用 npm)时出现以下错误:

> leveldown@2.1.1 install /root/apps/authentication/node_modules/leveldown
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=10.16.3 runtime=node arch=x64 platform=linux)
gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /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:198:13)
gyp ERR! stack     at maybeClose (internal/child_process.js:982:16)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Linux 4.18.0-80.11.2.el8_0.x86_64
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /root/apps/authentication/node_modules/leveldown
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
npm WARN auth@1.0.0 No description
npm WARN auth@1.0.0 No repository field.
npm WARN auth@1.0.0 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@2.1.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the leveldown@2.1.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!     /root/.npm/_logs/2020-01-08T21_40_49_710Z-debug.log

似乎 python 无法在 CentOS 8 上编译...欢迎任何帮助

仅供参考,我没有直接使用 leveldown,但它是 PouchDB 的依赖项

您已经安装了 Python 3,但是您的 运行 代码需要 Python 2。您可以安装 python2 包,然后您可以指示你的 npm 安装过程使用 /usr/bin/python2 而不是 /usr/bin/python.

如果这不可能,您应该能够将 /usr/bin/python 符号链接到 /usr/bin/python2。默认情况下,CentOS 8 没有 /usr/bin/python(它只有 python2python3 命令),所以这应该是无害的。


注意 Python 2 刚刚达到 end of life。此时仍需要 Python 2 的任何软件可能已经有一段时间没有看到更新了。