NPM Install Issues due to running Python 3 [Solved]

Ran into some hiccups while running NPM install on the Animal Kingdom app as I was using a version 3 of Python…gave an error like:

gyp ERR! configure error
gyp ERR! stack Error: Command failed: /anaconda3/bin/python -c import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack File “”, line 1
gyp ERR! stack import sys; print “%s.%s.%s” % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:299:12)
gyp ERR! stack at ChildProcess.emit (events.js:193:13)
gyp ERR! stack at maybeClose (internal/child_process.js:999:16)
gyp ERR! stack at Socket.stream.socket.on (internal/child_process.js:403:11)
gyp ERR! stack at Socket.emit (events.js:193:13)
gyp ERR! stack at Pipe._handle.close (net.js:614:12)
gyp ERR! System Darwin 18.5.0

Solved it by setting NPM to use version 2 of Python like this:

npm config set python python2.7

If you write print() function in a program and someone using Python 2.x tries to run it, they will get an error. To avoid this, it is a good practice to import print function :

from __future__ import print_function

The from future import print_function ; to bring the print function from Python 3 into Python 2.x. Now your code works on both Python 2.x and Python 3.x . The future statements need to be near the top of the file because they change fundamental things about the language, and so the compiler needs to know about them from the beginning.