How to run installed python script?

I used distutils to install my python package using this setup.py:

import distutils.core args = { 'name' : 'plugh', 'version' : '1.0', 'scripts' : [ "scripts/plugh" ], 'packages': [ "plugh" ], } d = distutils.core.setup( **args ) 

On linux / mac, it works as expected:

 % plugh hello world % 

In windows, the script "plugh" does not start:

 C:\Python25\Scripts>plugh 'plugh' is not recognized as an internal or external command, operable program or batch file. C:\Python25\Scripts> 

I found a bug report at http://bugs.python.org/issue7231 that the \ Scripts directory was not added to PATH when installing python, so I applied the workaround described in this ticket (i.e. add C: \ Python25 \ Scripts to PATH)

 C:\Python25\Scripts>path PATH=c:\Python25\Scripts;C:\Program Files\Legato\nsr\bin;C:\WINDOWS\system32;C:\ WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\QuickTime\QTSystem\;c:\python2 5;c:\local;C:\WINDOWS\system32\WindowsPowerShell\v1.0 

Is this something that just doesn't work on Windows? And if so, how exactly should you use python scripts on a Windows machine?

I assume that I could detect Windows and add to the list an additional script called "plugh.bat" containing something like:

 @echo off c:\python25\python.exec c:\python25\scripts\plugh %1 %2 %3 %4 %5 %6 %7 %8 %9 

but is this really the right answer? I would think that with all the settings that distutils contains for windows, there would be a better answer than that.

+6
python windows packaging distutils
source share
2 answers
Window

use the file extension to determine how it will work.

Name your file plugh.py and use plugh.py at the prompt to invoke it.

+6
source share
  • If you use ActivePython , it will already add the C:\PythonXY\Scripts to your %PATH% (additionally ActivePython 2.6 adds PEP 370 %APPDATA%\Python\Scripts to %PATH% ) during installation.

  • To deploy scripts on a Windows machine, it is better to use Distribute , which will take care of installing the EXE wrappers for your scripts and calling the real Python that your package was installed with (to avoid conflict with multiple Python installations - so calling your script the end of .py is simply not enough) . For more information on this topic, read the entry points in the Distribute Documentation section.

+5
source share

All Articles