The issue arises because the Node.js package you're trying to install is using Python version 3.13, which isn't officially released, so it’s likely due to a misconfiguration or an environment conflict. You can resolve this by explicitly setting your project or shell environment to use Python 3.10.16 (the version installed via Homebrew). Here's how to do it:
Verify the installation:
brew info python@3.10You should see the installation path, something like:
/opt/homebrew/opt/python@3.10
Ensure the binary is present:
ls /opt/homebrew/opt/python@3.10/binSet the PATH to prioritize Python 3.10 binaries:
export PATH="/opt/homebrew/opt/python@3.10/bin:$PATH"Verify the version being used:
python3 --versionIt should now return 3.10.16.
Node.js uses Python for building certain native dependencies via node-gyp. You can specify the correct Python version for Node.js as follows:
Set Python 3.10 as the default version for Node.js builds:
npm config set python /opt/homebrew/opt/python@3.10/bin/python3If you want to set the Python version only for a specific project, use:
npx node-gyp --python /opt/homebrew/opt/python@3.10/bin/python3Now, try running npm install in your project directory:
npm installIf the issue persists, clear the node_modules folder and reinstall:
rm -rf node_modules
npm installTo avoid resetting the PATH every time you open a shell, add the export line to your shell configuration file:
-
For
bash: Add this to~/.bashrc:export PATH="/opt/homebrew/opt/python@3.10/bin:$PATH"
-
For
zsh(default for macOS): Add this to~/.zshrc:export PATH="/opt/homebrew/opt/python@3.10/bin:$PATH"
Reload the shell:
source ~/.zshrc- By modifying the
PATH, you're ensuring Python 3.10 is used in your shell and is prioritized over other versions. - By configuring
npmto use Python 3.10 explicitly, you're ensuring Node.js native modules are built with the correct Python version.
If this still doesn't solve the problem, double-check your Node.js dependencies for hardcoded Python version requirements or conflicting configurations.
**NOTE**
Finally setting a python version in .npmrc file worked
python=/opt/homebrew/opt/python@3.10/bin/python3.10