我使用 distutils 安装我的 python 包,这个 setup.py :
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>
我在http://bugs.python.org/issue7231发现了错误报告,即安装 python 时 \Scripts 目录未添加到 PATH,因此我应用了该票证中描述的解决方法(即添加 C:\Python25\Scripts到路径)
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 为 Windows 包含的所有自定义项,会有比这更好的答案。