codex-storage / codex-contracts-eth

Ethereum smart contracts for Codex
Other
5 stars 8 forks source link

Fixing `npm install` failure when using python 3.12+ #95

Open elcritch opened 3 months ago

elcritch commented 3 months ago

I got a new machine recently and have been setting up my dev environment again. When I run npm install on the codex master branch with node 18.15.0 I'm getting build errors. I've added the errors below for others to find.

It appears to be due to my Python version which is Python 3.12 which doesn't bundle distutils by default anymore.

I was able to resolve the issue by running brew install python-setuptools. You can see stackoverflow for more info.

Unfortunately I'm not aware of how to resolve this for all users. Possibly updating some node deps would use updated python dependencies (gotta love rabbit trails ;)). Otherwise it might make sense to add a note in Codex or here.

npm ERR! code 1
npm ERR! path /Users/elcritch/projs/status/nim-codex/vendor/codex-contracts-eth/node_modules/ganache-core/node_modules/utf-8-validate
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using node-gyp@9.3.1
npm ERR! gyp info using node@18.15.0 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.12.2 found at "/opt/homebrew/opt/python@3.12/bin/python3.12"
npm ERR! gyp info spawn /opt/homebrew/opt/python@3.12/bin/python3.12
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   '/Users/elcritch/.asdf/installs/nodejs/18.15.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/elcritch/projs/status/nim-codex/vendor/codex-contracts-eth/node_modules/ganache-core/node_modules/utf-8-validate/build/config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   '/Users/elcritch/.asdf/installs/nodejs/18.15.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/elcritch/Library/Caches/node-gyp/18.15.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/elcritch/Library/Caches/node-gyp/18.15.0',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args   '-Dnode_lib_file=/Users/elcritch/Library/Caches/node-gyp/18.15.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=/Users/elcritch/projs/status/nim-codex/vendor/codex-contracts-eth/node_modules/ganache-core/node_modules/utf-8-validate',
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! Traceback (most recent call last):
npm ERR!   File "/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py", line 42, in <module>
npm ERR!     import gyp  # noqa: E402
npm ERR!     ^^^^^^^^^^
npm ERR!   File "/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 9, in <module>
npm ERR!     import gyp.input
npm ERR!   File "/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 19, in <module>
npm ERR!     from distutils.version import StrictVersion
npm ERR! ModuleNotFoundError: No module named 'distutils'
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:325:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 23.3.0
npm ERR! gyp ERR! command "/Users/elcritch/.asdf/installs/nodejs/18.15.0/bin/node" "/Users/elcritch/.asdf/installs/nodejs/18.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/elcritch/projs/status/nim-codex/vendor/codex-contracts-eth/node_modules/ganache-core/node_modules/utf-8-validate
npm ERR! gyp ERR! node -v v18.15.0
npm ERR! gyp ERR! node-gyp -v v9.3.1
npm ERR! gyp ERR! not ok

Environment details:

OS: macOS 14.3.1 m3 python: 3.12 node: 18.15.0

gmega commented 3 months ago

This seems to be a long standing problem with Macs - there are a number of ways in which you may end up with a Python without setuptools (e.g. when using homebrew and updating from an older version). I guess having that as a FAQ entry somewhere wouldn't hurt.