8

我使用 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 包含的所有自定义项,会有比这更好的答案。

4

2 回答 2

6

windows uses the extension of the file to determine how it will run.

Name your file plugh.py and use plugh.py on the prompt to call it.

于 2009-12-01T23:19:26.263 回答
5
  1. 如果您使用ActivePython,它会在安装过程中将目录添加到C:\PythonXY\Scripts您的%PATH%(ActivePython 2.6 额外添加PEP 370%APPDATA%\Python\Scripts%PATH%)。

  2. 为了在 Windows 机器上部署脚本,最好使用Distribute,它将负责为您的脚本安装 .exe 包装器调用安装包的实际 Python(以避免与多个 Python 安装冲突——因此将您的脚本命名为 end 。 py 是不够的)。有关此主题的更多信息,请阅读分发文档中的入口点

于 2009-12-20T20:10:47.830 回答