hmenyus / node-calls-python

Call Python from NodeJS directly in-process without spawning processes
MIT License
245 stars 23 forks source link

Symbol not found in flat namespace #17

Closed wobsoriano closed 2 years ago

wobsoriano commented 2 years ago

Hey, this is an awesome module! I am on M1 Pro and was getting this error:

node:internal/modules/cjs/loader:1187
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/Users/tmp/dalle-playground/node_modules/node-calls-python/build/Release/nodecallspython.node, 0x0001): symbol not found in flat namespace '_PyBool_Type'
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1187:18)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/tmp/dalle-playground/node_modules/node-calls-python/index.js:4:25)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Followed the installation instructions and installed the needed stuff. Copied the example usage.

Any help would be much appreciated!

hmenyus commented 2 years ago

Could you share your OS, compiler version, python version and node/node-gyp version? Thanks

wobsoriano commented 2 years ago

OS: Monterey 12.4 (21F79) node-gyp version: v9.0.0 node version: v16.14.2 python version: 3.9.12 Apple clang version 13.1.6 (clang-1316.0.21.2.5) Target: arm64-apple-darwin21.5.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

hmenyus commented 2 years ago

Could you run this and attach the output? otool -l /Users/tmp/dalle-playground/node_modules/node-calls-python/build/Release/nodecallspython.node

wobsoriano commented 2 years ago

Hi, thanks. I got this

error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool-classic: 
can't open file: /Users/tmp/dalle-playground/node_modules/node-calls-python/build/Release/nodecallspython.node (No such file or directory)
hmenyus commented 2 years ago

You may have deleted the file which is present in the error message above (dlopen(....)) Please search nodecallspython.node and run otool -l on that file. Thanks

wobsoriano commented 2 years ago

So I switched to Node v18, and got this error instead

❯ node index
node:internal/modules/cjs/loader:1196
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: dlopen(/Users/wobsoriano/tmp/dalle-playground/node_modules/node-calls-python/build/Release/nodecallspython.node, 0x0001): tried: '/Users/wobsoriano/tmp/dalle-playground/node_modules/node-calls-python/build/Release/nodecallspython.node' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))
    at Module._extensions..node (node:internal/modules/cjs/loader:1196:18)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/wobsoriano/tmp/dalle-playground/node_modules/node-calls-python/index.js:4:25)
    at Module._compile (node:internal/modules/cjs/loader:1112:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1166:10)
    at Module.load (node:internal/modules/cjs/loader:988:32)
    at Module._load (node:internal/modules/cjs/loader:834:12) {
  code: 'ERR_DLOPEN_FAILED'
}

Node.js v18.4.0

Looks like an architecture problem. I'm on M1 Pro

hmenyus commented 2 years ago

Try to specify the arch for npm like these: npm install --target_arch=arm64 node-calls-python npm install --arch=arm64 --target_arch=arm64 node-calls-python

Honestly this problem is not related to the addon. Looks like node-gyp compiles for x64 but you run node arm64. Please also note that you need python for arm64 as well. Otherwise you may run rosetta2 to run x64 code on your M1 Pro.

wobsoriano commented 2 years ago

npm install --target_arch=arm64 node-calls-python npm install --arch=arm64 --target_arch=arm64 node-calls-python

Did the trick, thanks!

changyongyong commented 1 year ago

Try to specify the arch for npm like these: npm install --target_arch=arm64 node-calls-python npm install --arch=arm64 --target_arch=arm64 node-calls-python

Honestly this problem is not related to the addon. Looks like node-gyp compiles for x64 but you run node arm64. Please also note that you need python for arm64 as well. Otherwise you may run rosetta2 to run x64 code on your M1 Pro.

I am on M1 and was still getting this error: node_modules/node-calls-python/build/Release/nodecallspython.node, 0x0001): symbol not found in flat namespace '_PyBool_Type' at process.func [as dlopen] (node:electron/js2c/asar_bundle:2:1822) at Module._extensions..node (node:internal/modules/cjs/loader:1226:18) at Object.func [as .node] (node:electron/js2c/asar_bundle:2:1822) at Module.load (node:internal/modules/cjs/loader:1011:32) at Module._load (node:internal/modules/cjs/loader:846:12) at f._load (node:electron/js2c/asar_bundle:2:13330) at Module.require (node:internal/modules/cjs/loader:1035:19) at require (node:internal/modules/cjs/helpers:102:18) at Object. (/Users/xx/workspace/gitlab/electron/demo/node_modules/node-calls-python/index.js:4:25) at Module._compile (node:internal/modules/cjs/loader:1141:14)