2

I'm having troubles installing Python 2.7.

Since I learned Python in one of my classes, I first learned Python 3 and currently have that installed on my computer (I'm using Windws 7).

I need Python 27 installed because I want to learn how to use Django and they currently only are Python2 compatible.

After I installed Python 2.7, I keep getting a syntax error when I try running Python 2.7:

file=sys.stderr syntaxerror: invalid syntax

I know it is because it is grabbing this file from my current Python 3 path.

How could I then resolve this? How can I make my Python27.exe grab all the files from the Python27 path and NOT the Python3 path. I'm very new to this and don't even know how to switch paths for exe files.

Thanks for the help!

G01
  • 421
  • 1
  • 4
  • 14
  • please post the details of your path: system path, user path, path variables (related to python), etc. – KobeJohn Jun 15 '12 at 16:30
  • My python folders are: C:\Python31 and C:\Python27....however...I do not know much about system paths/path variables. This is also part of my question...how can I get Python3 to grab the files associated with Python3 to run? And similarly, make Python27 only grab the files it needs for Python27 to run? If it is any help, I chose everything default when I installed Python3 and 27 so they should all be standard. – G01 Jun 15 '12 at 16:32
  • Python Portable might be anohter solution... – user541686 Jun 16 '12 at 00:53
  • Did you ever get this working? – KobeJohn Jun 26 '12 at 06:12
  • Consider accepting an answer? – ShivanKaul Apr 27 '16 at 03:53

2 Answers2

1

You could do this by changing the filenames of your python.exe files to 'python' and 'python3', and then adding paths to both your versions to your $PATH environment variable.

Refer: How to make shortcut work from PATH

Community
  • 1
  • 1
ShivanKaul
  • 687
  • 1
  • 8
  • 21
0

The long term answer to your question is probably virtualenv. It will allow you to use various versions of python and various setups of the same version of python without them stepping on each others' toes. I believe it will even be packaged by default from an upcoming version of python 3.

Try uninstalling python 3 and see if you can get things to work with python 2. If they do, then try reinstalling python 3 and don't tell it to be the default python installation (there is some kind of option like that during installation I believe). If python 2 still doesn't work after uninstalling python 3, then you've got some other strange problem going on.

General setup for multiple pythons on windows

The accepted answer on this question shows how to set it up without virtualenv and be able to selectively run whichever version of python you want.

*Path settings *

If you want to mess around with the path directly, you can try this. This might help if you somehow have added paths of python libraries directly to your path by removing them and resetting it to just having the python main directories.

  • In windows 7: start button --> right-click on computer --> properties --> advanced system settings --> environment variables --> system variables
  • (disclaimer: follow the tutorial above if you don't want to risk deleting something important) delete anything that looks like a path related to python
  • in the main "Path" variable, add c:/python27;c:/python31 or whatever paths you have.
  • in each python folder, make a shortcut to python.exe named python27 / python31
  • open a new command prompt and try the command "python27" or "python31"
Community
  • 1
  • 1
KobeJohn
  • 7,390
  • 6
  • 41
  • 62
  • How can I get a hold of the path for the versions of Python? I'm fairly new to this... Thanks for helping KJ! – G01 Jun 15 '12 at 16:45
  • @PaulTref they are in `C:\Python27` and `C:\Python32` respectively (or Python31 for version 3.1 and so on) – Nisan.H Dec 12 '12 at 22:51