Computing: DOS, OS/2 & Windows Programming

FreeDOS: Installing PythonD on top of DJGPP.


Python is an interpreted, interactive, object-oriented programming language. PythonD is a 32-bit, multi-threaded, networking- and OpenGL-enabled Python interpreter for DOS and Windows. For details, you may want to have a look at the PythonD page of the CADDIT Website Knowledge Base. Unfortunately, the download links are dead, as are most of the links on other PythonD sites.

This tutorial describes the installation of PythonD 2.2.1 on FreeDOS 1.3 RC5. It should also work with other versions of FreeDOS, and probably will with MS-DOS, PC-DOS, and others. It is not impossible to do a standalone install of PythonD, but to make things simpler, and even more to be able to use all of the possibilities that PythonD offers, an installation on top of DJGPP is recommended. To follow the tutorial, it is supposed that you have installed DJGPP, as I describe in my tutorial Installing and running DJGPP on FreeDOS. I actually use DJGPP 2.0.5 and I did install it at C:\DJGPP.

You can download PythonD 2.2.1 from the Vetusware website. It's a ZIP archive, that will have to be unpacked into the DJGPP installation folder (C:\DJGPP in our case).

Installing PythonD.

Several features of PythonD use long file names (in opposition to the usual DOS 8-character names). This means, that you'll have to load an LFN driver. DOSLFN.COM is part of FreeDOS and should normally be present in your FreeDOS\bin directory; if you use MS-DOS or PC-DOS, you can download the driver from the Ibiblio website. The driver is not only necessary when running PythonD, but also when installing it. In fact, some PythonD subdirectory names have more than 8 characters, in particular the "site" directory is called SITE-PYTHON. The FreeDOS unzipper (UNZIP.EXE; be sure to use that one, and not the one I used when installing DJGPP!) is able to handle such names, and does it this way: If there is a LFN driver installed, the unzipper uses it to extract the files with their full names; if there isn't a driver, filenames are truncated at 8 characters. You can see the difference on the screenshots below: On the left, no LFN driver was used, and the folder SITE-PYTHON has been created as SITE-PYT; on the right DOSLFN was loaded when the archive was unpacked and the folder has been created with its full name (displayed as SITE-P~1 here, because the DOS DIR command does not support long file names). If you install PythonD without the LFN driver loaded, scripts using the "import" instruction will abort with the message 'import site' failed.

PythonD on FreeDOS: Subdirectories with 8-character folder names (will result in 'import site failed' errors)
PythonD on FreeDOS: Subdirectories with full folder names (will properly import from SITE-PYTHON folder)

I burned the ZIP download archive onto a CDROM (aka created an ISO), that is mounted as drive F: on my FreeDOS machine. Now, two steps to install PythonD:

  1. Installing the long file name driver:
        lh doslfn
  2. Extracting the files of the PythonD download archive (on the CDROM) into the DJGPP installation folder:
        c:
        cd djgpp
        unzip f:\pythond.zip

PythonD on FreeDOS: Extracting the PythonD files into the DJGPP directory (with LFN enabled)

There are lots of files, thus this will take a moment. When done, you should have the directory structure and subdirectory names as shown on the screenshot on the right above.

That's it! One of the advantages of doing the installation on the top of DJGPP is that there isn't any need to set Python specific environment variables. In particular, no need to set the PythonD home directory (PYTHONHOME).

Testing the PythonD installation.

Here a very simple script (showing that function calls work well), that I called area.py and that I stored into the D:\Devel\Python directory.

    # Circle area function
    def area(x, y = 3.14):
        a = y * x * x
        return a
    # Main program
    a = area(10)
    print "area for radius 10 = ", a

If I said that we don't need to set specific environment variables for Python, that does not mean that we don't need to set any environment variables at all. With PythonD running on top of DJGPP, environment variables have to be set the same way as you do when you run the GNU C or C++ compiler:
    SET PATH=C:\DJGPP\BIN;%PATH%
    SET DJGPP=C:\DJGPP\DJGPP.ENV

The Python interpreter is called PYTHON.EXE and to run our program we execute the interpreter with the python source file name as argument. So, being in the directory, where you stored area.py, run the command python area.py.

PythonD on FreeDOS: Running a simple Python program

Loading the LFN driver and setting the environment variables needs to be done only once and not to have to type it each time you use DJGPP on a newly booted system, you can add the commands to your AUTOEXEC.BAT file or create a DJGPP.BAT file, that you run as needed. I'll give details about my PythonD related batch files further down in the text.

Using FTE as PythonD editor.

I did not find an IDE for Python on DOS, neither did I try to use PythonD with SET's Editor (as I did for Perl; cf Installing and running Perl 5 on FreeDOS). You can use the standard FreeDOS editor, of course, or even write your source code in Notepad++ on your Windows machine. Here another possibility: the FTE Text Editor. It has two major advantages compared to the FreeDOS editor:

FTE exists for many platforms and can be downloaded from the FTE Text Editor page at the Sourceforge website. You'll have to download 2 files: a common package, necessary with all other archives (in my case fte-20010819-common.zip), and a platform-specific package, here the one for DJGPP (in my case fte-20010819-djgpp2.zip).

I unpacked the download archives onto two floppy diskettes. On FreeDOS, I created a new directory (C:\FTE) for the files from both archives. The actual directory being C:\, enter
    mkdir fte
The, I copied the whole folder structure, resulting from the extraction of fte-20010819-common.zip to this directory. The actual directory being A:\FTE, enter
    xcopy *.* c:\fte /i /h /e /q
And finally, I copied the files, resulting from the extraction of fte-20010819-djgpp2.zip to this directory. The actual directory being A\:, enter
    copy *.* c:\fte

In order to make things easier for me, I created two batch files py#.bat and pyinit.bat, stored in C:\FREEDOS\BATCH, a directory where I keep all my batch files, and that together with C:\FREEDOS\BIN is added to the path in my AUTOEXEC.BAT. I have similar files for Free Pascal, Free Basic, Perl, Visual Basic, Microsoft COBOL and FORTRAN, Borland Pascal, and others. The reason, why the names of these files end in a number sign is to ensure that I run my file and not a possibly existing file with the same name that is part of the software installation files. The way how it works is simple: The batch file with #-name checks if the DEVEL environment variable is set to a value indicating the corresponding programming language. If not, it calls the init batch file, that sets the DEVEL variable, the path, other environment variables needed, and (if required) loads the LFN driver. Then, it sets the path to the programming language specific subdirectory of D:\DEVEL (containing all my development files), and finally starts the IDE or editor used with this programming language. This may seem a little bit complicated, but the batch files do everything automatically and all that yourself have to do to make the directory with your Python scripts the current one and launch FTE is entering py#.

Here the content of my py#.bat file:

    @echo OFF
    if not "%devel%"=="py" call pyinit.bat
    D:
    cd \DEVEL\PYTHON
    FTE.EXE

And the content of pyinit.bat:

    @echo OFF
    lh doslfn.com
    set PATH=C:\DJGPP\bin;C:\FTE;%path0%
    set DJGPP=C:\DJGPP\DJGPP.ENV
    set DEVEL=py

The environment variable PATH0 is set equal to PATH in AUTOEXEC.BAT and never changes. A simple way to "remove" the directories added to the path before.

Note: I'm not sure which files of the DJGPP PythonD actually uses. Just to be sure to avoid problems if you use PythonD on a system with G77 installed in a way as I describe in my tutorial Installing and running Gnu Fortran on FreeDOS, you should modify pyinit.bat as follows:

    @echo OFF
    lh doslfn.com
    set PATH=C:\DJGPP\bin;C:\FTE;%path0%
    set DJGPP=C:\DJGPP\DJGPP.ENV
    set DEVEL=py
    del C:\DJGPP\BIN\AR.EXE
    del C:\DJGPP\BIN\AS.EXE
    del C:\DJGPP\BIN\GCC.EXE
    del C:\DJGPP\BIN\LD.EXE
    del C:\DJGPP\LIB\CRT0.O
    copy C:\DJGPP\BIN\AR.DJC C:\DJGPP\BIN\AR.EXE
    copy C:\DJGPP\BIN\AS.DJC C:\DJGPP\BIN\AS.EXE
    copy C:\DJGPP\BIN\GCC.DJC C:\DJGPP\BIN\GCC.EXE
    copy C:\DJGPP\BIN\LD.DJC C:\DJGPP\BIN\LD.EXE
    copy C:\DJGPP\LIB\CRT0.DJC C:\DJGPP\LIB\CRT0.O

So, lets type py# and see what happens. The FTE Text Editor opens, and as a difference with most other editors, does not show an empty file, or the last file opened, but the contents of the current directory. As my batch files set this one to my Python development folder, a list of my Python scripts is displayed. On the screenshot below, you recognize area.py, used as example before, and a new example called cmd_arguments.py. Note that this script has a name with more than 8 characters and nevertheless is fully displayed; if you wonder why, just have a look at the code in pyinit.bat above.

PythonD on FreeDOS: FTE Text Editor - Directory listing (file selection)

You can use the up and down arrow-keys to select an item in the list and then hit ENTER to open the file; you can also use the mouse. The screenshot shows the content of my sample script cmd_arguments.py. I suppose that you agree that that's lots more convenient than the display without color highlighting, as in the FreeDOS editor.

PythonD on FreeDOS: FTE Text Editor - Python source code with color highlighting

The script is an example, not more, not less. But, its execution is a good test for our PythonD environment setup. The source includes the import of "sys" and, as I said above, imports only work correctly if long file names are correctly handled. Maybe, you would like to try out the script on your FreeDOS machine ... here is the code:

    # Command line arguments
    import sys
    print "Number of command line arguments = ", len(sys.argv)
    if len(sys.argv) > 0:
        print "Arguments are:"
        for i in sys.argv:
            print i

I don't think that it's possible to run the Python interpreter from within FTE. On the other hand, you can use Tools > Shell on the FTE menu bar to open a shell, where you can run the script, entering the command python cmd_arguments.py. To return to FTE, simply type exit.

PythonD on FreeDOS: Running a Python script in the shell opened from within FTE Text Editor

If you find this text helpful, please, support me and this website by signing my guestbook.