How to force npm to use python version you want?

Few days ago I tried to install Angular framework in my new project so I had to prepare all of the environment for it. I installed latest node.js with npm as default package manager for win10 which succeed relatively quick. Then in my project directory I have created package.json file with devdependencies and angular dependencies which I wanted to use later. And here is where the problem started.

NPM – python version forcing

I opened terminal with admin rights and I chose my project directory and typed “npm install” that should run all the magic. After a few rows of processing it turned out that npm needs python in version 2.7 as default to perform some builds and all the process crashed. Solution? There are a couple of them. I could try to add a new environmental path to Python 2.7 – it needs to be installed first obviously. NPM has this nice management ability from terminal side that I like. So it was possible to use the explicitly given Python version as well. Happily before I had installed Python 3 as default.

To install stuff using npm with specific python version all I had to do was to specify Python version as a npm parameter:

npm install --python=python3.6.5

Problems with python were solved. Processing went on, but then another riddle appeared – looks like Sass needs some legacy .Net SDK version to run its build. Another crash, another Q&A on stackoverflow. And I found the easiest solution for windows – directly from node.js github. The Windows Build Tools! 🙂

npm install --global --production windows-build-tools

The trick above solved the rest of problems and with python parameter I managed to run and install everything.

Leave a Reply

Your email address will not be published. Required fields are marked *