我用的distutils安裝我的Python包,這個setup.py:如何運行已安裝的python腳本?
import distutils.core
args = {
'name' : 'plugh',
'version' : '1.0',
'scripts' : [ "scripts/plugh" ],
'packages': [ "plugh" ],
}
d = distutils.core.setup(
**args
)
在Linux/MAC,它按預期工作:
% plugh
hello world
%
在Windows中,腳本 「plugh」 不不運行:
C:\Python25\Scripts>plugh
'plugh' is not recognized as an internal or external command,
operable program or batch file.
C:\Python25\Scripts>
我發現的bug報告,http://bugs.python.org/issue7231,當你安裝python的\ Scripts目錄未添加到PATH,所以我申請的解決方法d在該票上標明(即添加C:\ Python25 \ Scripts到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
這是什麼東西,只是不適用於Windows?如果是這樣,你應該如何在Windows機器上使用Python腳本?
我想,我可以檢測到Windows,並添加額外的腳本列表中,被稱爲「plugh.bat」包含類似:
@echo off
c:\python25\python.exec c:\python25\scripts\plugh %1 %2 %3 %4 %5 %6 %7 %8 %9
而且是真的在這裏正確的答案?我會認爲,在distutils包含的所有窗口定製中,會有比這更好的答案。
順便說一句,該參數順序%1%2%3%4%5%6%7%8%9可以用%*來代替如果你只需要通過所有批輸入到pyhton腳本(或任何其他可執行文件) – dreikanter 2012-06-03 13:33:13