-1

I installed python3 first on my PC. Now python launches python3 in a command prompt. When I tried to run a node app with a python2 dependency, I got an error about syntax (it was using the old print syntax):

gyp ERR! stack Error: Command failed: 
C:\Users\User\AppData\Local\Programs\Python\Python38-32\python.EXE -c import 
sys; print "%s.%s.%s" % sys.version_info[:3];

But I don't know how to make python point to python2.

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
  • 1
    Windows uses a PATH variable, although I don't use Windows all that often anymore, so I can't remember exactly where to find it -- but you will want to ensure that the python2 path is in the PATH before the python3.exe... – kojiro Sep 30 '20 at 17:52
  • To make python point to python2, go to `python2` directory and copy `python2.exe` as `python` in the same directory, then add this folder to `PATH` – Shivam Jha Sep 30 '20 at 17:54
  • 1
    This is an OS question. You need to search for your Python2 installation -- likely under the Programs\Python folder -- and either alter your PATH variable to point there, or create an alias (shortcut) for python2. See your OS documentation for how to handle those variables. – Prune Sep 30 '20 at 17:55
  • @kojiro - this is the right answer. It was the ORDER of the path variables – JacobIRR Sep 30 '20 at 17:58

4 Answers4

0

You need to change your Windows environment variable to point to the python you want to use.

That's most likely where node is going to find the path for a usable python.exe.

0

You just need to change the env variable

similar question reference

Coleone
  • 63
  • 2
  • 12
0

Alternate solution: Never run python. The Windows solution, assuming Python 3 was installed with administrative privileges (so it could install the Python launcher), is to run:

 py -2

to run Python 2, and

 py -3

to run Python 3. The launcher was created specifically because the name is always python.exe on Windows, so only one version could ever be found in the PATH; the launcher grants access to all installed copies without manipulating PATH. Doesn't even require extra typing (py -2 being shorter than python).

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
0

The Python installer installs PyLauncher unless you deselected it. Don't add python to the PATH. py.exe (the launcher) is installed in the path already (C:\Windows by default).

py -2   # launches latest python 2 installed.
py -3   # launches latest python 3 installed.
py -3.6 # launches Python 3.6.

The PY_PYTHON environment variable can be set, e.g. set PY_PYTHON=3.6 to select a default python when running just py; otherwise, it will choose the latest version of Python installed.

You can also use #!python2 in a script for it to use that version of Python when double-clicked in Explorer or run without a specific switch (py script.py).

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251