[Tutor] Re: Two (not so) dumb questions

RASTM2 at aol.com RASTM2 at aol.com
Fri Sep 5 07:03:16 EDT 2003


> 
> Date: Tue, 2 Sep 2003 16:29:00 +0700
> From: "Robin Hood"

> Robin Hood writes
> 
> Two dumb questions:
> 
> 1. How do you set the PATH environment variable for python under windows 98
> (So that I can import modules which aren't located in the same folder as
> python itself)
> 


Hi Robin,
The short answer to your first (not so) dumb question : 

Make a copy of your autoexec.bat file located in your
top directory. This is normally the "C:\" directory.

Call the copy something like autoexec.bak or .old or 
dot anything that isn't going to destroy an already existing file.

Open the autoexec.bat file. (Keep in mind that there may be 
nothing in this file to begin with and that's okay.)

On the line after the last entry in the file, type something like this 
(using your version of Python of course):

PATH=C:\Python23\;C:\Python23\lib;%path%

and save the file. Restart the computer.

Example of my Python path in my autoexec.bat is:
PATH=c:\Python23\;c:\Python23\lib;c:\pymy;%path%

This line has to be typed exactly as shown 
or your machine could lock up.
This line has the word PATH=, 
followed by the new path you want to add,
followed by a colon. 
Follow the entire string by a percent sign,
followed by the word path,
followed by a percent sign.

Notice that each individual path has to be followed by a colon.
Notice also that the entire path line is followed by %path%. 
Now, the reason for this is that you already have a pre-existing
PATH set up on your machine. 
( you can see it by typing "path" at a dos prompt 
( also try typing "set" to see all environment variables))
The %path% "environment variable"
adds the pre-existing path to your new 
path that you just created for Python.
Please also notice, in the example of my Python path, 
I also have included the path to the directory where 
I keep my scripts, modules, and programs that I write.

> 2. Currently, to execute a python script I have to right click it, choose
> "edit with IDLE" then choose "run script" from one of the drop down menus.
> If I just double click on a python script. It automatically executes under
> the DOS interpreter, and then closes itself too quickly to see what the
> results were. Is it possible to change this? 


Yes.

(That is, make it so that the
> program doesn't automatically close the DOS Prompt after its finished
> executing, or get it to automatically execute under the Windows IDLE)
> 
> *****A Network is the Opposite of a Hierachy*****

Robin, for my next trick...
For Python programs that included DOS prompt output.

Open a dos prompt and navigate to your program directory
that you would like to run. 
Now that you have set up your python path (above) you can 
just type something like...

C:\pymy\>python "Your_program_name_here".py

and the program will execute. When it ends you will still have 
the output in the dos window until you close the window yourself.

If you haven't set the path variable yet, you just have to type the
path to the python version you want to run this proggy with.
C:\pymy\>C:\Python23\python "your_proggy".py


HTH
Regards,
Ray St.Marie <Rastm2 at aol.com>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20030905/a8262e4a/attachment.htm


More information about the Tutor mailing list