[Tutor] running as generic file type

Alan Gauld alan.gauld at freenet.co.uk
Thu Dec 22 14:14:01 CET 2005


Hi Eli,

> I'm very new to python, I created my first program, saved it as .py.
> I wanted to show it to my friends and I tested running it on another
> computer, one without python, and it didn't work,

That's because Python is an interpreted language so it needs an interpreter
to be present. This is the same as Java and most Visual Basic programs,
the difference being that Microsoft provide Visual Basic and Java 
interpreters
on Windows as standard.

One of the easiest ways for you to write code that works on any machine
is to use Jython. It is a vesion of Python written in Java that comes with a
compiler for converting the Python code into a Java program. That will
then run on any computer with Java installed. The snag is that some of
the standard modules that come with Python don't work with Jython!
(Thats because Java provides similar modules so you can use them instead).
Most beginner programs will work in Jython but as you progress you might
start hitting problems. But by then you are ready for option 2...

Another way to get the programs to run is to convert the python program
into a standalone executable file (a .exe) which can be done using a
downloadable tool called py2exe. Py2exe just bundles a copy of the
interpreter and all the modules you use into one file. Unfortunately
this is not the simplest tool for a beginner to use... Also it creates quite
big files - too big for a floppy disk.

Of course if your friends had Apple Macs or Linux boxes then Python
would be installed already.

And there is a version of Python for Microsoft's new .NET framework
called IronPython. But I haven't tried it and don't know how well it works.
Also your friends will need to have the .NET framework installed.

Finally, you could just install Python on your friends PCs too and
maybe get them interested in programming :-)

So there is no perfect answer (yet), sorry. But there are some options
for you to try...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list