Problem
While trying to install npm packages for a Vue.js project, I encountered errors related to the
1 | deasync |
1 | distutils |
1 | distutils |
Diagnosis
- The project was using an older version of Node.js (v16.17.1).
- The system Python (version 3.13) did not include the distutils module.
- npm was not correctly configured to use a Python version with distutils available.
Solution
The issue was resolved by following these steps:
- Update Node.js to the latest LTS version:bashCopy
1nvm use v20.11.1
- Verify Python 3.11 installation (which includes
):bashCopy1distutils1/opt/homebrew/opt/python@3.11/bin/python3.11 --version
- Confirm
availability in Python 3.11:bashCopy1distutils1/opt/homebrew/opt/python@3.11/bin/python3.11 -c "import distutils; print('distutils is available')"
- Set npm to use Python 3.11:bashCopy
1export npm_config_python=/opt/homebrew/opt/python@3.11/bin/python3.11
- Clear npm cache and reinstall dependencies:bashCopy
1npm cache clean --force rm -rf node_modules package-lock.json npm install
Key Takeaways
- Python Version Matters: Newer versions of Python (3.12+) have removed
, which some npm packages rely on for compilation.1distutils
- Node.js and npm Compatibility: Ensure you’re using a compatible Node.js version for your project and npm version.
- npm Configuration: Properly configuring npm to use the correct Python version can resolve many installation issues.
Additional Notes
- Consider using a Python version manager like
for easier management of multiple Python versions.1pyenv
- For projects requiring specific Python versions, consider creating a virtual environment.
- Regularly update your development tools and be aware of major changes in new versions that might affect your projects.
Remember, while this solution worked for my specific setup, your mileage may vary depending on your system configuration and project requirements.