[Tutor] Tkinter and python

Dave Kuhlman dkuhlman at rexx.com
Sun Oct 8 18:20:10 CEST 2006


On Sun, Oct 08, 2006 at 08:36:31PM +0530, Arun Kumar PG wrote:
> Hi,
> 
> You can try:
> 
> >>import sys
> >>sys.path.append('<absolute_path_to_program_dir>')
> >>import <module.py>
> 
> Or else you can append the path to global PYTHONPATH environment variable
> and whenever you will type:
> 
> python <module.py> on the command prompt/bash shell the script gets
> executed.
> 

Not true, if I understand you correctly.  PYTHONPATH affects where
Python looks for modules to be imported.  But if I type the
following at the command line:

    $ python mymodule.py

it is the shell (in my case bash) that looks for mymodule.py, not
Python.  It analogous to my typing:

    $ vi mymodule.py

or (trying to avoid a fight between vi and emacs fanatics):

    $ emacs mymodule.py

Neither vi nor emacs try to find mymodule.py; the (bash or other)
shell does.

So perhaps a solution to the problem is to make mymodule.py
executable and put it somewhere on your path.  Then execute it by
typing at the command line:

    $ mymodule.py

Now the shell will run it just like any other executable script and
it will use Python as the interpreter for that script.

How you make the script executable probably depends on which shell
you are using.  For bash, you could do the following:

1. Insert the following line as the first line of your script:

       #!/usr/bin/env python

2. Change the priveleges of the script to make it executable. 
   Example:

       $ chmod u+x mymodule.py

3. Put mymodule.py on your path, that is, in a directory that is in
   your PATH environment variable.  Alternatively, add the path to
   the directory containing mymodule.py to your PATH environment
   variable.

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list