小编Mar*_* S.的帖子

如何运行已安装的python脚本?

我使用distutils来安装我的python包,使用这个setup.py:

import distutils.core

args = {
    'name' :            'plugh',
    'version' :         '1.0',
    'scripts' :         [ "scripts/plugh" ],
    'packages':         [ "plugh" ],
}

d = distutils.core.setup(
    **args
)
Run Code Online (Sandbox Code Playgroud)

在linux/mac上,它按预期工作:

% plugh
hello world
% 
Run Code Online (Sandbox Code Playgroud)

在Windows上,脚本"plugh"不会运行:

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

C:\Python25\Scripts>
Run Code Online (Sandbox Code Playgroud)

我在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
Run Code Online (Sandbox Code Playgroud)

这个东西在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
Run Code Online (Sandbox Code Playgroud)

但这真的是正确答案吗?我会想到,对于windows中包含distutils的所有自定义,会有比这更好的答案.

python windows packaging distutils

7
推荐指数
2
解决办法
3942
查看次数

标签 统计

distutils ×1

packaging ×1

python ×1

windows ×1