0

I have python 3.4 installed and I use this as my main version. I also have python 2.7 in order to run legacy scripts. Python 3.4 is used as my PATH variable, and I want to keep it this way. Now when I try to run python I get this error:

Error Message

In my console I can still run py3.exe, but I can't run python.exe (version 3.4). What can I do to fix this? My PATH is configured correctly to python 3.4 - there are no references to 2.7:

PATH Variables

This error only occurred after installed python 2.7, and the console simply does not recognise the path

Invisible Hippo
  • 124
  • 1
  • 1
  • 9
  • 1
    well you are using python 2.7 in the command prompt? – DZDomi Feb 08 '18 at 19:38
  • You have more than just `PATH` defined. You probably have `PYTHONPATH` and/or `PYTHONHOME` set to point to 3.4. If it was just `PATH` pointing to 3.4 you wouldn't be having these issues because it's the other two variables that control the module search path. – Steven Rumbalski Feb 08 '18 at 19:47
  • And there it is in your edit. – Steven Rumbalski Feb 08 '18 at 19:49
  • Hi Steven, could you elaborate? I want to run python 3 as my default, which is why I have PATH and PYTHONPATH set to point to 3.4. For some reason, the installation of python 2.7 changed something and python 3 will not run at all. – Invisible Hippo Feb 08 '18 at 19:51
  • Get rid of `PythonPath`. Change the Python stuff in your `PATH` to `C:\Python34;C:\;Python34\Scripts;C:\Python27;C:\;Python27\Scripts`. In `C:\Python34` make a **copy** of `python.exe` and call it `python3.exe`. In `C:\Python27` make a **copy** of `python.exe` and call it `python2.exe`. Run whichever Python from anywhere on the command line by typing `python2` or `python3`. Taken from [this answer](https://stackoverflow.com/a/22626734/1322401) and incorporating the comments so as to not break pip or the ability to uninstall python. – Steven Rumbalski Feb 08 '18 at 20:17
  • My guess is that your Python 2.7 installation set an variable that broke your 3.4 installation. Remember that you can both system level and user level variables, so look in both for stray `PYTHONPATH` and `PYTHONHOME`. I'm confident you don't need them. I have both Python 2.7 and 3.6 installed on Windows and don't have them defined and don't have any problems. – Steven Rumbalski Feb 08 '18 at 20:27
  • Hi Steven, I made the changes you suggested and entering python2 launches V2.7 as expected, but when I enter python3 it launches V2.7 as well... – Invisible Hippo Feb 08 '18 at 20:31
  • 1
    I decided to completely uninstall python 3.4 and install python 3.6. Using Steven's suggestion to rename the python.exe names to python2 and python3 respectively it now works correctly. Something with my python 3.4 completely broke. – Invisible Hippo Feb 08 '18 at 20:49

1 Answers1

1

This is because your path is pointing to the installation of your 3.4 version. Therefore even the 2.7 version will try to access those 3.4 files.

If you want to have 2 different version of python, that are completely separated, you can use Anaconda or virtualenv to encapsulate your python interpreter with its own libraries.

Adrien Logut
  • 812
  • 5
  • 13
  • Hello, Please review my edits and see if you can find a solution – Invisible Hippo Feb 08 '18 at 19:47
  • You might have altered your path by installing python2.7. `python` now correspond to the 2.7 version. My best advice is to uninstall 2.7 and use virtualenv or Anaconda to create a 2.7 env. that's is the safest way to have both versions. – Adrien Logut Feb 08 '18 at 19:51