Python Development

Summary

PythonŽ is a free of charge, open source, dynamic, object-oriented programming language that can be used for many kinds of software development. It offers strong support for integration with other languages and tools, comes with extensive standard libraries, and can be learned in a few days. Many Python programmers report substantial productivity gains and feel the language encourages the development of higher quality, more maintainable code.

Created with matplotlib Created with matplotlib Created with pyGame Created with pyGame Created with Blender Created with Blender

1.  Recommended Installation

This section describes how to install the scripting language “Python” and some useful extensions on a Windows operating system using Internet Explorer.

Note: Follow this tutorial carefully. If you need any help, you can e-mail the wiki administrator

  1. Download the python installer by clicking on the following link: http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi.
  2. When the internet explorer warning pops up, select Open.
  3. Follow the instructions on the screen.
  4. Download python image library (PIL) installer by clicking on the following link: http://effbot.org/downloads/PIL-1.1.5.win32-py2.4.exe.
  5. When the internet explorer warning pops up, select Open.
  6. Follow the instructions on the screen.
  7. Go to the following address: http://prdownloads.sourceforge.net/numpy/Numeric-24.2.win32-py2.4.exe?download.
  8. Select a mirror to download the python Numeric library by clicking on any of the Download links on the right-hand side of the page.
  9. When the internet explorer warning pops up, select Open.
  10. If the link did not work, select another mirror (it takes a few seconds for the internet explorer warning to pop up).
  11. Follow the instructions on the screen.
  12. Go to the following address: http://prdownloads.sourceforge.net/numpy/numpy-0.9.8.win32-py2.4.exe?download.
  13. Select a mirror to download the python NumPY library by clicking on any of the Download links on the right-hand side of the page.
  14. When the internet explorer warning pops up, select Open.
  15. If the link did not work, select another mirror (it takes a few seconds for the internet explorer warning to pop up).
  16. Follow the instructions on the screen.
  17. Go to the following address: http://prdownloads.sourceforge.net/matplotlib/matplotlib-0.87.4.win32-py2.4.exe?download.
  18. Select a mirror to download the python matplotlib library by clicking on any of the Download links on the right-hand side of the page.
  19. When the internet explorer warning pops up, select Open.
  20. If the link did not work, select another mirror (it takes a few seconds for the internet explorer warning to pop up).
  21. Follow the instructions on the screen.
  22. Download the python game engine (PyGame) by clicking on the following link: http://www.pygame.org/ftp/pygame-1.7.1release.win32-py2.4.exe.
  23. When the internet explorer warning pops up, select Open.
  24. Follow the instructions on the screen.

2.  Creating “.EXE” Files from Python Scripts

You have your python code working… Great! But now, you want it to run on any computer. Not all the computers will have a python interpreter installed, how to solve it?

If you intend to distrubute your code for windows users, there is a module called py2exe, that allows you to generate a windows executable from your python code.

The steps to compile your program (in an oversimplified list) are:

  1. Download py2exe if you have not done it yet from http://sourceforge.net/project/showfiles.php?group_id=15583. Remember to choose the version that matches your python version. It is important to nothe that if you are running windows, python from cygwin is not compatible with py2exe, you will need the python version distributed by active state, or the version for windows that you can find at python.org.
  2. Install your py2exe by running the “.exe” file that you just downloaded
  3. cd to the directory where your program is located
  4. Create a setup.py (that gives information to the py2exe module about the program that you are creating). If your program is “example.py”, the most basic version of this file will be:

Contents of setup.py (example)

from distutils.core import setup
import py2exe

setup(console=['example.py'])
  1. Run the py2exe module over the setup script that you just created, run:
    python setup.py py2exe

This will create a folder called “dist”, send that folder to your favourite friend, he will have to run the executable called as the program that you compiled (for our example, it would be “example.exe”). have fun!

2.1  Links