What kind of setup do people use to run both python 2.6 and python 3.0 on the same windows machine?
Why do you want to do it? Everything that's in 3.0 is in 2.6, you can use the new features in 3.0 with from __future__ import
. Run 2.6 until you're ready to upgrade to 3.0 for everything, then upgrade. You're not intended to have multiple versions of Python on the same machine. If you really want to, you can specify alternative install directories, but I really don't see how it's worth the hassle.
No problem, each version is installed in its own directory. On my Windows box, I have C:\Python26\
and C:\Python31\
. The Start Menu items are also distinct. Just use the standard installers from the Python Programming Language Official Website, or the ready-to-install distributions from ActiveState.
A direct way to select the wanted version is to name it explicitly on the command line.
C:\> C:\Python25\python ver.py
2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)]
C:\> C:\Python31\python ver.py
3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)]
Where ver.py
is:
import sys
print (sys.version)
-You could use a batch file to launch with the appropriate version.
-Eclipse with pydev allows you to choose which version to launch with.
-Re-associate the .py/.pyw extension with your preferred version.
Virtualenv is the solution of choice on Unix and Mac platforms.
virtualenv is a tool to create isolated Python environments.
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.4/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.
Or more generally, what if you want to install an application and leave it be? If an application works, any change in its libraries or the versions of those libraries can break the application.
Also, what if you can't install packages into the global site-packages directory? For instance, on a shared host.
I have not tried this, but the presence of documentation relating to use in Windows makes me think that it now works on Windows.
Interesting, but I want to be able to learn the 3.0 syntax (print()) etc but still need to maintain some 2.5 and 2.6 code..
Python has __future__
"Future statement definitions", which make new features available in older versions of Python, the print function is one of them:
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
>>> from __future__ import print_function
>>> print("Example", end=" Hurray!\n")
Example Hurray!
Another big Python 3.0 change is the default string becoming Unicode:
>>> from __future__ import unicode_literals
>>> type('abc')
<type 'unicode'>
>>> 'a'
u'a'
Most of the others are now part of Python 2.6, so aren't of interest (like the with_statement
). The only one I didn't mention is from __future__ import braces
to allow "C like" if(){}
braces