node.js - 如果不是 libtool_re.match(line) 而不是 libtool_re5.match(line): TypeError: cannot use a string pattern on a bytes-like object
问题描述
我试图从节点项目中调用 C/C++ 代码,当我npm install
构建它时给了我奇怪的类型错误
我将 Anaconda 与 Python 3.7 一起用作全局 Python。我也安装了 python 2.7
所以我所做的就是跑
npm config set python /usr/local/bin/python
但我仍然收到此错误
npm install ✔ master
> app@0.0.0 install /Users/aa/binding
> node-gyp rebuild
CC(target) Release/obj.target/nothing/node_modules/node-addon-api/src/nothing.o
LIBTOOL-STATIC Release/nothing.a
Traceback (most recent call last):
File "./gyp-mac-tool", line 611, in <module>
sys.exit(main(sys.argv[1:]))
File "./gyp-mac-tool", line 28, in main
exit_code = executor.Dispatch(args)
File "./gyp-mac-tool", line 43, in Dispatch
return getattr(self, method)(*args[1:])
File "./gyp-mac-tool", line 246, in ExecFilterLibtool
if not libtool_re.match(line) and not libtool_re5.match(line):
TypeError: cannot use a string pattern on a bytes-like object
make: *** [Release/nothing.a] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/Users/aa/anaconda/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack at emitTwo (events.js:126:13)
gyp ERR! stack at ChildProcess.emit (events.js:214:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Darwin 18.0.0
gyp ERR! command "/Users/abhimanyuaryan/anaconda/bin/node" "/Users/aa/anaconda/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/aa/binding
gyp ERR! node -v v8.11.3
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@0.0.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@0.0.0 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/aa/.npm/_logs/2018-10-25T10_13_17_726Z-debug.log
******我的源代码:******
绑定.cpp
#include <napi.h>
using namespace Napi;
String Hello(const CallbackInfo& info) {
return String::New(info.Env(), "world");
}
void Init(Env env, Object exports, Object module) {
exports.Set("hello", Function::New(env, Hello));
}
NODE_API_MODULE(addon, Init)
绑定.gyp
{
"targets": [
{
"target_name": "native",
"sources": [
"binding.cpp"
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
],
"dependencies": [
"<!(node -p \"require('node-addon-api').gyp\")"
],
"cflags!": ["-fno-exceptions"],
"cflags_cc!": ["-fno-exceptions"],
"defines": ["NAPI_CPP_EXCEPTIONS"]
}
]
}
包.json
{
"name": "app",
"version": "0.0.0",
"private": true,
"gypfile": true,
"dependencies": {
"node-addon-api": "^1.5.0"
}
}
解决方案
Node.js 和 node-gyp 现在支持 Python 3。Python 2 于 2020 年 1 月 1 日死亡。
推荐阅读
- python-3.x - 是否还创建了内置模块的 pyc 文件?
- google-tag-manager - 可以在gtm脚本上方定义dataLayer,然后将数据推送到gtm脚本下方的dataLayer吗?
- r - 按基于条件创建的组汇总列值
- angular - 是否可以从角度的应用程序代码中强制进行硬应用程序更新(Ctrl + F5 浏览器模拟)?
- python - Python:表达式返回不同的响应 a=a+1 vs a+=1
- python-3.x - 漂亮的汤不解析嵌套表数据
- c# - 如何修复循环的结果
- python-3.x - 计算一组数据点的标准差
- c# - 如何在 C# 中全局声明 XDocument 命名空间?
- c# - 当前上下文中不存在名称“item”