12

I'm having some issues with the node-gyp package, and I believe it's because I need to use python 2.7 rather than python 3.

I have set-up my PATH environment variables so that when I do python --version the output is Python 2.7.16.

However, in the same terminal, when I go to yarn install my project. It fails, and I can see the output of the logs is:

Command: node-gyp rebuild
Arguments:
Directory: /Users/myname/Documents/myproject
Output:
gyp info it worked if it ends with ok
gyp info using node-gyp@5.0.5
gyp info using node@12.14.0 | darwin | x64
gyp info find Python using Python version 3.7.3 found at "/Users/myname/anaconda3/bin/python"

I am also using nvm. Catalina 10.15.2. Node 12.14.0. NVM 0.33.11.

Why does my terminal version show me as using 2.7, but then the logs show the command node-gyp rebuild as using 3.7.3? If I've already set-up my environment variables, what can I change to rectify this? Is it something to do with nvm?

JazzyGreen
  • 159
  • 2
  • 3
  • 8

4 Answers4

9

If experiencing this issue on an M1 Mac, see the accepted answer to this question (basically for Node versions older than 15, you need to open Terminal using Rosetta):

nvm install node fails to install on macOS Big Sur M1 Chip

This solution worked for me (on an M1 MacBook Pro) when the other answers here did not work.

most200
  • 874
  • 1
  • 8
  • 9
5

MacOS M1

  1. Install pyenv with brew to manage different python versions: brew install pyenv.

2.eval "$(pyenv init -)".

  1. if you going install version lower than 3.y, open your terminal with rosetta.

  2. List all installable versions with pyenv install --list

  3. pyenv global 2.7.18

Allan Bontempo
  • 117
  • 1
  • 5
-1

Ran into the same issue with nvm. What fixed it for me was uninstalling my current node version using nvm uninstall v and then installing it again using nvm install v. After this the python version was detected perfectly. Think this is due to config caching upon new node version installation or something like that.

picklepirate28
  • 143
  • 1
  • 1
  • 10
-5

Solved! You can do:

npm install --python=python2.7

or set it to be used always:

npm config set python python2.7

Pinched from here => How to use a different version of python during NPM install?

JazzyGreen
  • 159
  • 2
  • 3
  • 8