Problema extraño con múltiples instalaciones de Python en Windows

I have 3 versions of Python (2.5, 2.7, 3.2) installed on a Windows machine, 2.5 being the default one (first in PATH and default for open action).

Now the weird thing appear when I run a python script with filename.py (without specifying the interpreter) or by clicking the file in Explorer: Python 2.5 is running the script (expected) BUT Python 2.7 PATH being inserted before the original system PATH.

Still if I look at the command line, it seems that Python 2.5 was executed.

Where is the first record in PATH (C:\Ptyhon27\) comming from, I can assure you this is added when the scripts runs, but by whom?

enter image description here

As you already observed I do have several versions of Python in PATH, this is not something anormal, because they can also have versioned executables instead and because Windows always picks the first one it the PATH.

preguntado el 08 de noviembre de 11 a las 12:11

3 Respuestas

Looking closely, it seems you have various versions of Python in your PATH environment variable.

The standard Python installer for Windows doesn't add itself to the PATH; I always do this manually for the version of Python I want to use by default. If you're using a different Python installer (such as ActiveState or Enthought) that may be the cause, but I haven't tried those.

In any case, you can edit your PATH environment variable manually and clean it up, leaving only the path to the version of Python you wish to be the default, as described aquí (scroll down a bit to get to the relevant section).

respondido 08 nov., 11:17

It's not something wrong to have several versions of python on PATH. - Sorin

What's the point of having several versions of Python in the PATH? True, it is technically not an error. However, this can only lead confusion and I can't think of any benefit. Running python or pythonw will use the executable from the first version of Python on the PATH and the others will never be used. - taleinat

Quizás te interese el Lanzador de Python para Windows project, a.k.a. PEP 397. Install it, and remove all Python dirs from PATH, leaving only the launcher one, and use py/pyw en lugar de python/pythonw.

respondido 08 nov., 11:17

Ahh, I think I have it! You didn't mention exactly how you're running Python...

Python adds the directory from which the command is run to the PATH! If you run it from the command line, this will be the directory in which the Python file you execute is located, or the directory you ran Python from if you just opened an interpreter. However, various tools, interpreters and development environments start up differently, and some of them will use a certain Python interpreter (depends on their configuration) and add its location to PATH.

If you want more help, please give a detailed description of how you're running Python when this happens.

respondido 08 nov., 11:23

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.