10

I'm new to programming and thought Python would be a good language to learn. Most of the tutorials I found were 2.7 based so I started to learn using that version. I've recently found a tkinter tutorial that I'd like to try out but I'm having a problem. If I run a script it will use Python 2.7 which contains Tkinter and not tkinter.

This problem made me think, how can I get my two versions to co-exist so I can program in both 2.x and 3.x?

akaGrim
  • 337
  • 2
  • 5
  • 13
  • 6
    I believe that Python 2 and Python 3 can coexist peacefully. What problem do you have with it? What operating system? – Rosh Oxymoron Jul 18 '11 at 18:44
  • 2
    I have Python 2.5, 2.6, 2.7, 3.0, 3.1 and 3.2 installed on my Windows box. What's the problem? – David Heffernan Jul 18 '11 at 18:48
  • You can name the version explicitly, if you have multiple versions installed. For instance, my (Linux) machine runs 2.4 when I call `python`, but I also can run 2.5 just by saying `python2.5` instead. – user812786 Jul 18 '11 at 18:49
  • 1
    For a [clean, official solution, install Python 3.3](http://stackoverflow.com/a/13297878/194586), which includes the [Python Launcher for Windows](http://blog.python.org/2011/07/python-launcher-for-windows_11.html) – Nick T Nov 08 '12 at 21:44
  • @akaGrim Which OS are you using? Linux? Windows? Mac? – jpaugh Jan 05 '18 at 23:51

5 Answers5

7

I'm not sure I understand your question, but I'll take a shot. I'm also assuming you're on Windows.

It's simple -- just install both. They will install to different directories, create different start menu folders, etc. I'd also reccomend PyWin32 for the PythonWin editor installed in both 2.7 and 3.2,

If you mean how do you write one script that works with either Python 2 or Python 3, look at http://docs.python.org/library/2to3.html

David
  • 15,894
  • 22
  • 55
  • 66
agf
  • 171,228
  • 44
  • 289
  • 238
  • 1
    I installed both on a Windows 8 computer, but when I run `python` on the commandline it gives me this `Fatal Python error: Py_Initialize: unable to load the file system codec File "C:\Python27\lib\encodings\__init__.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax`. This is obviously running python3 and then for some reason it runs stuff in python2 and causes an error. How do I separate them, while being able to specify where `python` goes? Like being able to switch. – CMCDragonkai Nov 14 '13 at 19:19
1
wget  <python download url>
tar xfvz Python-X.Y.Z.tar.gz
cd Python-X.Y.Z
configure --prefix=/path/to/python-x.y.z
make install
0

There is limited support for some of the Python 3 functionality in Python 2. >= 6 (using the __future__ module and py2to3) as well as (even more limited, in my optinon) Python 3 to Python 2. >= 6 with the py3to2, but for a very large percentage of code -- there simply isn't a way to make it work.

In along with the addition of generators (making some function calls from 2.x simply not work in Python 3) many of the major frameworks have not made it to Py3k. Django comes to mind, and, if I'm not mistaken Hg is also in Python 2 still.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
0

You don't specify what operating system you're on. It's been my experience that installing multiple Python versions alongside one another tends to just work. For example on Ubuntu it's simply a matter of installing both the 2.x and 3.x packages (using sudo apt-get install or Ubuntu Software Centre):

aix@aix:~$ python2.6
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

aix@aix:~$ python3
Python 3.1.2 (release31-maint, Sep 17 2010, 20:27:33) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I even have a third version (an EPD build) installed on the same box:

aix@aix:~$ python2.7
Enthought Python Distribution -- www.enthought.com
Version: 7.0-2 (64-bit)

Python 2.7.1 |EPD 7.0-2 (64-bit)| (r271:86832, Nov 29 2010, 13:51:37) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

It depends on what you are trying to do. You can have them coexist because 3.2 is backwards-compatible. Now you can install both versions on your computer 3.2 and 2.7, but 3.2 unfortunately will have to be used in IDLE....ugh.... Just install both and then depending on which one you want to use. Run that IDLE for either one or the other.

Now if you are meaning that you want more stable version that can be professionally done, go with 2.7 ( I have done otherwise, but if you run into problems 2.7 is more supported.

If you want the more cutting edge stuff, go with 3.2. Either one you go with works with about eveyrthing. If it doesn't, give it a month or two and the rest of the world will catch up.

TheChes44
  • 648
  • 1
  • 10
  • 21