0

I have python 2.7 installed. I want to use python 2.4 to run python code. Is it possible?

Black_Hat
  • 943
  • 1
  • 9
  • 12

3 Answers3

1

Either directly use the Python 2.4 interpreter to run it, or modify the programs she-bang line to point to the interpreter you wish to use.

Note that there's many things in common use in recent python (any/all, the 1 if 2 else 3 syntax, as well as major stdlib and language changes) that may cause your program to experience difficulties.

It's also worth noting that a lot of the common 3rd party modules require at least 2.5 and some of those are even dropping that and only guaranteeing 2.6+ compatibility.

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
  • Hey... I have created my program using v2.7 and want to check whether it runs successfully or not on v2.4, I want to run it with python v2.4. but on my system V2.7 is installed. So, Is it possible to check it for 2.4? – Black_Hat Jun 28 '13 at 09:15
  • @Black_Hat sure - install 2.4 (either via a system package if you can find one) or compile your own. Then just try running it. – Jon Clements Jun 28 '13 at 09:24
1

You can install Python 2.4 as well. Any of the minor versions, 2.4, 2.5, 2.6, etc. can live side by side.

Code you write for 2.4 will also run on Python 2.7, albeit that you may hit some deprecation warnings. If you are using the 2.7 interpreter to write 2.4 code, you'll need to be careful that you don't use syntax and modules that have been added in newer Python versions.

To see what has been added, look at the What's new documentation; there is a document for each minor version:

You specifically want to look for syntax changes and for new modules to avoid.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • ok.. fine.. got that. How can I know how many python version are running side by side in my system? And how can I use a particular version? – Black_Hat Jun 28 '13 at 09:17
  • Each python minor version can be started by using the version as part of the command: `python2.4`, `python2.7`. Check your package manager to see what is already installed or available to install through the package manager. You can install Python from source too, or use the [Python Buildout](https://github.com/collective/buildout.python) to build almost all versions of python for you in one place. – Martijn Pieters Jun 28 '13 at 09:23
0

There are a few things that can bite you. Some syntactic changes have happened since 2.4, so you may get syntax errors. The standard library is bigger in 2.7, so you may have some things missing. The docs generally lists the version of python when things were added, and can be great help in making sure things will run on different python versions. Generally, syntax and libraries are forward compatible, so if you have to support 2.4, I would write using 2.4 and things should work with 2.7. The same is not true in reverse.

Perkins
  • 2,409
  • 25
  • 23
  • python v2.7 have some new modules. So I just want to run my python program with v2.4 to check compatibility issue. But i have v2.7 installed on my system. How can I check then? – Black_Hat Jun 28 '13 at 09:11
  • Install 2.4 (you can have multiple versions installed without issue), then run it with 2.4, on windows you'll need to specify in cmd.exe c:\python24\python.exe , on linux, just python2.4 – Perkins Jul 28 '13 at 04:08