Larry has correctly stated the steps to set this up on UNIX style systems
such as OS X and Linux. Sadly this approach does not work on XP.

I am not a Windows expert and I don't play one on TV but a variation on
James' original idea would probably work.

Put your script in C:\somewhere\reasonable\script.py

In each directory put a myscript.bat with a line something like:
python C:\somewhere\reasonable\script.py <whatever the syntax for batch
parameters is>

As I said I'm not a Windows expert. Anyone who knows more than me (not
hard!) please feel free to point out what an idiot I am.

On Fri, Apr 8, 2011 at 2:37 PM, Larry Bugbee <[email protected]> wrote:

> Alex's script should work, but FWIW, I've had good luck with:
>   1- #!/usr/bin/env python
>   2- removing the .py from the name (optional but makes for easier typing)
>   3- give the script execute permission  (chmod +x ...)
>   3- ensuring the script's directory is in the searchlist ($PATH)
> ...on OSX.  IIRC it worked on Linux as well.
>
> Larry
>
>
> On Apr 8, 2011, at 2:11 PM, Smartboy wrote:
>
>  In Linux and OSX you can create a bash script to do this for you. For
> example:
>
> #!/bin/sh
> python /path/to/script.py $@
>
> As for Windows, I think you can do something similar, I don't know batch
> very well.
>
> Alex
>
> On 04/08/2011 02:02 PM, James Fort wrote:
>
> Hello SeaPIG,
>
>
> I wonder if anyone knows how to address the following issue.  I looked in
> a book and Googled for a while and couldn't find what I'm looking for.
>
>
> I want to have a directory or set of directories that contain Python
> scripts which I can execute from anywhere in my file system.  Right now,
> I'm concerned with Windows XP, but I may want to do the same in Mac OSX and
> Linux in the future.  Essentially, I want to by able to type:
>
>
> currentDir>>>python script.py arg1 arg2
>
>
> Where arg1 and arg2 might be files in the current directory that act as
> inputs to the script and script.py is a script that resides in another
> directory.
>
>
> Here are some ideas I considered:
>
>
>
>    - Setting the PYTHONPATH variable to include a directory where
>    script.py is stored.  This did not work.  It seems to only work for
>    importing modules once the Python interpreter is already invoked.
>    - I read online and in a book that you can set "#!/usr/bin/python" as
>    the first line in a script, assuming that this is the full path to the
>    interpreter, put the script in /usr/bin or any other directory to which 
> PATH
>    points, and run the script using ">>>script.py".  I read that this is
>    only an option in Unix, however, and it doesn't allow me to specify the
>    version of Python I want to use as would be possible if I prefixed the
>    script submission command with ">>>python26 script.py".  This also
>    precludes me from using ">>>run script.py" from within Ipython.
>
>
> Does anyone know how to handle this?  I noticed that I run the same script
> by copying the script into the directories in which I want to run it, but
> when I make revisions to the script, I have different versions sitting in
> different directories, which is becoming very difficult to manage.
>
>
> Thanks,
> James
>
>
>


-- 
Some radio waves were modulated in the creation of this email.

Reply via email to