How do I make Python 2.x and 3.x coexist?

I am new to programming and thought Python would be a good language to learn. Most of the tutorials I found were based on 2.7, so I started to learn this version. I recently found a tkinter tutorial that I would like to try, but I have a problem. If I run the script, it will use Python 2.7, which contains Tkinter, not tkinter.

This problem made me think, how can I combine my two versions so that I can program in both 2.x and 3.x versions?

+7
python
Jul 18 '11 at 18:40
source share
5 answers

I'm not sure I understand your question, but I will take a picture. I also assume that you are on Windows.

It's simple - just install both. They will be installed in different directories, create different folders in the menu, etc. I would also recommend PyWin32 for the PythonWin editor installed in both version 2.7 and 3.2,

If you mean how you write a single script that works with either Python 2 or Python 3, see http://docs.python.org/library/2to3.html

+5
Jul 18 2018-11-18T00:
source share
— -
wget <python download url> tar xfvz Python-XYZtar.gz cd Python-XYZ configure --prefix=/path/to/python-xyz make install 
+1
Jul 18 '11 at 18:45
source share

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

In addition to adding generators (some function calls from 2.x just don't work in Python 3), many of the main frameworks haven't reached Py3k. Django comes to mind, and if I'm not mistaken, Hg is also in Python 2.

0
Jul 18 2018-11-18T00:
source share

You do not indicate which operating system you are on. In my experience, installing multiple versions of Python next to each other tends to work. For example, on Ubuntu, it is just a matter of installing 2.x and 3.x packages (using sudo apt-get install or Ubuntu Software Center):

 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 (EPD build) installed in the same field:

 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. >>> 
0
Jul 18 2018-11-18T00:
source share

It depends on what you are trying to do. You can make them coexist because 3.2 is backward compatible. Now you can install both versions 3.2 and 2.7 on your computer, 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 this IDLE for one or the other.

Now, if you mean that you need a more stable version that can be professionally executed, go with 2.7 (I did otherwise, but if you run into problems, then 2.7 is more supported.

If you want more advanced things, go to 3.2. Or you go with work with eveyrthing. If not, give him a month or two, and the rest of the world will catch up.

0
Jul 18 '11 at 20:16
source share



All Articles