hmenyus / node-calls-python

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

Installation Problem [Mac Silicon / python 3.11 / Conda] #63

Closed ttessarolo closed 11 months ago

ttessarolo commented 12 months ago

Hi – I'm trying to install node-calls-python using conda as env manager for Python on Mac and I have the following issue:

npm ERR! code 1
npm ERR! path /Users/tommasotessarolo/Developer/ARES/ares-test/enhanced-data-scraper/node_modules/node-calls-python
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! CXX(target) Release/obj.target/nodecallspython/src/addon.o
npm ERR!   CXX(target) Release/obj.target/nodecallspython/src/pyinterpreter.o
npm ERR!   SOLINK_MODULE(target) Release/nodecallspython.node
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.4.0
npm ERR! gyp info using node@20.9.0 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.11.5 found at "/Users/tommasotessarolo/anaconda3/bin/python3.11"
npm ERR! gyp info spawn /Users/tommasotessarolo/anaconda3/bin/python3.11
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'make',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/tommasotessarolo/Developer/ARES/ares-test/enhanced-data-scraper/node_modules/node-calls-python/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/tommasotessarolo/Library/Caches/node-gyp/20.9.0/include/node/common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=/Users/tommasotessarolo/Library/Caches/node-gyp/20.9.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/tommasotessarolo/Library/Caches/node-gyp/20.9.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/tommasotessarolo/Developer/ARES/ares-test/enhanced-data-scraper/node_modules/node-calls-python',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp info spawn make
npm ERR! gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
npm ERR! ld: library 'python3.11' not found
npm ERR! clang: error: linker command failed with exit code 1 (use -v to see invocation)
npm ERR! make: *** [Release/nodecallspython.node] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack     at ChildProcess.onExit (/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:514:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Darwin 23.1.0
npm ERR! gyp ERR! command "/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/bin/node" "/Users/tommasotessarolo/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/tommasotessarolo/Developer/ARES/ares-test/enhanced-data-scraper/node_modules/node-calls-python
npm ERR! gyp ERR! node -v v20.9.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

the problem seams to be here --> ld: library 'python3.11' not found

any advice?

hmduc1603 commented 12 months ago

I have the same error

hmenyus commented 11 months ago

have you installed python-dev package? if you run 'python3-config --ldflags --embed' it shows a list of directories: -Lxxxxxx. please check if xxxxxxx has libpython3.11. for further investigation please attach the output of the command above.

ttessarolo commented 11 months ago

@hmenyus the command "python3-config --ldflags --embed" produced the following output:

-L/Users/tommasotessarolo/anaconda3/lib/python3.11/config-3.11-darwin -lpython3.11 -ldl -framework CoreFoundation

the directory "/Users/tommasotessarolo/anaconda3/lib/python3.11/config-3.11-darwin -lpython3.11" have the following files:

drwxr-xr-x   14 tommasotessarolo  staff     448 Nov 29 17:05 .
drwxr-xr-x  211 tommasotessarolo  staff    6752 Nov 29 17:05 ..
-rw-r--r--    1 tommasotessarolo  staff  119251 Nov 29 17:05 Makefile
-rw-r--r--    2 tommasotessarolo  staff   11182 Oct  3 12:41 Setup
-rw-r--r--    2 tommasotessarolo  staff     878 Oct  3 12:41 Setup.bootstrap
-rw-r--r--    2 tommasotessarolo  staff      41 Oct  3 12:41 Setup.local
-rw-r--r--    2 tommasotessarolo  staff    5378 Oct  3 12:41 Setup.stdlib
drwxr-xr-x    3 tommasotessarolo  staff      96 Nov 29 17:05 __pycache__
-rw-r--r--    2 tommasotessarolo  staff    3483 Oct  3 12:41 config.c
-rw-r--r--    2 tommasotessarolo  staff    1752 Oct  3 12:41 config.c.in
-rwxr-xr-x    2 tommasotessarolo  staff   15358 Oct  3 12:41 install-sh
-rwxr-xr-x    2 tommasotessarolo  staff    9262 Oct  3 12:41 makesetup
-rwxr-xr-x    1 tommasotessarolo  staff    2067 Nov 29 17:05 python-config.py
-rw-r--r--    2 tommasotessarolo  staff    2720 Oct  3 12:41 python.o
hmenyus commented 11 months ago

it seems that python-config with conda returns an incorrect directory to pass to the linker. I have added a workaround/hack inside the module. You can try 1.8.1 version.

ttessarolo commented 11 months ago

@hmenyus OK thanks now it works!