# Pythonpath on w98

Peter Hansen peter at engcorp.com
Sat Sep 23 18:14:28 CEST 2000

Larry Whitley wrote:
>
> I'd like to be able to say
>
> python xxx.py

Wouldn't you prefer to just say xxx from any directory?  It's easier
that way.  See below.

> from the command line in any directory on my w98 laptop.
>
> I've added the python directory to the path and am finding python.exe
> without problem.
>
> It's my guess that Python wants to look in PYTHONPATH for the location of
> xxx.py.   But, I defined PYTHONPATH and set it equal to the directory
> containing xxx.py but it did no good (set PYTHONPATH=c:\Utility\Python). I
> have Python 1.6 and PythonWin installed.  When I look at the registry a
> PythonPath key and several subkeys are defined under
> HKEY_LOCAL_MACHINE/Software/Python/PythonCore/1.6/PythonPath.  So whatever I
> do with PYTHONPATH, I don't want to screw up those entries.

Python looks in PYTHONPATH for modules that you import, but the command
line doesn't seem to look there for scripts.  If you run python
interactively and type 'import xxx' while PYTHONPATH points to where
xxx.py resides, Python will find it (and execute it!).  You could
perhaps say 'python -c "import xxx"' instead but that's grim.

On the other hand, a much cleaner way to do this kind of thing is to use
good ol' DOS batch files.  Make a standard directory for utilities (I
usually use c:\bin) and ensure that is in your PATH (DOS PATH, not
PYTHONPATH).  Create a batch file called xxx that contains:

@echo off
python x:\full\path\to\xxx\directory\xxx.py %1 %2 %3 %4 %5 %6 %7 %8 %9

Yes, ugly as can be but for most little utilities this is more than
enough and not a great burden to create.

Then you just type xxx anywhere and things work.  The %1 %2 etc. above,
in case you aren't experienced with batch files, allow arguments on the
command line (only up to 9 :-( ) to be passed through to the script.

There are a few enhancements you can make, including finding the
PythonLauncher.exe program that was posted a while back (sorry, no URL
handy) which lets you avoid creating the above batch file at all,
provided you are willing to have the launcher program (renamed to
xxx.exe) and the script both reside in a directory on the path.

--
Peter Hansen