This error occurs when npm tries to compile a native module using node-gyp but cannot find Python. The solution is to install Python and ensure it is accessible in your system PATH.
The "spawn python ENOENT" error occurs when npm attempts to build a native Node.js module that requires compilation. Many npm packages include C/C++ code that must be compiled during installation using node-gyp, and node-gyp requires Python to run the build scripts. ENOENT stands for "Error NO ENTry" and indicates that the system could not find the requested executable. In this case, node-gyp is trying to spawn a Python process, but the `python` command is not available in your system's PATH environment variable. This error is especially common on Windows, where Python is not pre-installed. On macOS and Linux, Python is usually available, but you may encounter issues if only `python3` is installed and the package expects `python`. The error also frequently appears in CI/CD pipelines and Docker containers that don't have Python or the necessary build tools pre-installed.
First, verify whether Python is installed and accessible from your terminal:
python --versionIf this fails, try:
python3 --versionIf neither command works, Python is not installed or not in your PATH. If only python3 works, you'll need to configure npm to use it (see step 3).
On Windows, also check:
where pythonOn macOS/Linux:
which python python3On Windows:
Option 1 - Using the official installer:
1. Download Python from https://www.python.org/downloads/
2. Run the installer and check "Add Python to PATH" during installation
3. Restart your terminal/PowerShell after installation
Option 2 - Using winget:
winget install Python.Python.3.12Option 3 - Using Chocolatey:
choco install pythonOn macOS:
# Using Homebrew (recommended)
brew install python
# Or install Xcode Command Line Tools (includes Python)
xcode-select --installOn Ubuntu/Debian:
sudo apt update
sudo apt install python3 python3-pipOn Fedora/RHEL:
sudo dnf install python3 python3-pipAfter installation, close and reopen your terminal, then verify with python --version or python3 --version.
If Python is installed but node-gyp cannot find it, tell npm where Python is located:
If python3 is your command (common on modern Linux/macOS):
npm config set python python3Or specify the full path:
# macOS/Linux
npm config set python /usr/bin/python3
# Windows (adjust path as needed)
npm config set python C:\Python312\python.exeUsing environment variable (useful for CI/CD):
export PYTHON=/usr/bin/python3
npm installOr on Windows PowerShell:
$env:PYTHON = "C:\Python312\python.exe"
npm installTo check your current npm Python configuration:
npm config get pythonNative modules also require C/C++ compilers. The error may mention Python first even if build tools are also missing.
On Windows:
# Install Visual Studio Build Tools (recommended)
npm install -g windows-build-toolsOr manually install:
1. Download "Build Tools for Visual Studio" from https://visualstudio.microsoft.com/downloads/
2. Select "Desktop development with C++" workload
3. Restart your terminal after installation
On macOS:
xcode-select --installOn Ubuntu/Debian:
sudo apt install build-essentialOn Fedora/RHEL:
sudo dnf groupinstall "Development Tools"If you have python3 but some packages expect python, you can create a symlink:
On Ubuntu/Debian:
sudo apt install python-is-python3Manual symlink (use with caution):
# Check where python3 is located
which python3
# Create symlink (example)
sudo ln -s /usr/bin/python3 /usr/bin/pythonOn macOS with Homebrew:
brew link pythonNote: Creating manual symlinks can interfere with system scripts that expect a specific Python version. The python-is-python3 package on Ubuntu is the safest approach.
For Docker builds, ensure your Dockerfile includes Python and build tools:
# Node.js with build dependencies (Alpine)
FROM node:20-alpine
RUN apk add --no-cache python3 make g++
# Node.js with build dependencies (Debian-based)
FROM node:20
RUN apt-get update && apt-get install -y python3 build-essential
# Set python3 as default python
RUN ln -sf /usr/bin/python3 /usr/bin/pythonFor GitHub Actions:
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm installFor GitLab CI:
image: node:20
before_script:
- apt-get update && apt-get install -y python3 build-essential
- npm config set python python3Some packages offer prebuilt binaries that avoid the need for compilation entirely:
# For node-sass, switch to the pure JavaScript alternative
npm uninstall node-sass
npm install sass
# For bcrypt, use the pure JavaScript version
npm uninstall bcrypt
npm install bcryptjs
# For sqlite3, try better-sqlite3 which has prebuilds
npm uninstall sqlite3
npm install better-sqlite3Check if the problematic package offers prebuilt binaries for your platform:
# Install with verbose logging to see if prebuild is used
npm install <package-name> --verboseMany packages now include prebuilt binaries via @prebuild/prebuildify, which eliminates the need for Python and compilers entirely.
### Platform-Specific Requirements
Windows is the most challenging platform for native module compilation:
- Requires Python 3.6+ (Python 2 is deprecated and may not work)
- Needs Visual Studio Build Tools (not the full IDE)
- The windows-build-tools npm package can install both Python and VS Build Tools, but it's deprecated and may fail on newer Windows versions
- For Windows 11, manually installing Python and VS Build Tools is more reliable
macOS requirements:
- Xcode Command Line Tools (xcode-select --install)
- Python comes with Xcode CLT but may need Homebrew's Python for newer versions
- On Apple Silicon (M1/M2/M3), ensure you're using the arm64 version of Node.js
Linux requirements:
- build-essential (gcc, g++, make)
- python3 and python3-pip
- Some packages may need additional dev libraries (e.g., libpng-dev for sharp)
### node-gyp Configuration
node-gyp can be configured globally:
# View current configuration
npm config list
# Set Python path globally
npm config set python /path/to/python
# For Windows, you may also need to set msvs_version
npm config set msvs_version 2022### Debugging Build Failures
Enable verbose node-gyp output:
npm install --verbose
# or
npm install --loglevel verbose 2>&1 | tee npm-install.logCheck the node-gyp debug log:
cat ~/.npm/_logs/*-debug.log### Using node-gyp Directly
If npm install consistently fails, try building with node-gyp directly:
cd node_modules/problematic-package
node-gyp rebuild --python=/usr/bin/python3### WSL2 Considerations
When using Windows Subsystem for Linux:
- Ensure you're running npm from within WSL, not from Windows
- Install Linux packages: sudo apt install python3 build-essential
- Don't mix Windows and Linux Node.js installations
- Use Linux file paths, not /mnt/c/ paths for your project
npm ERR! code ENOAUDIT npm ERR! Audit endpoint not supported
How to fix "npm ERR! code ENOAUDIT - Audit endpoint not supported"
npm ERR! code EBADDEVENGINES npm ERR! devEngines.runtime incompatible with current node version
How to fix "npm ERR! code EBADDEVENGINES - devEngines.runtime incompatible with current node version"
npm ERR! code ETOOMANYARGS npm ERR! Too many arguments
How to fix "npm ERR! code ETOOMANYARGS - Too many arguments"
npm ERR! code EINVALIDTAGNAME npm ERR! Invalid tag name: tag names cannot contain spaces
How to fix "npm ERR! code EINVALIDTAGNAME - tag names cannot contain spaces"
npm ERR! code E400 npm ERR! 400 Bad Request
How to fix "npm ERR! code E400 - 400 Bad Request" error