Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何运行已安装的python脚本?_Python_Windows_Packaging_Distutils - Fatal编程技术网

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

如何运行已安装的python脚本?,python,windows,packaging,distutils,Python,Windows,Packaging,Distutils,我使用distutils安装python软件包,使用setup.py: import distutils.core args = { 'name' : 'plugh', 'version' : '1.0', 'scripts' : [ "scripts/plugh" ], 'packages': [ "plugh" ], } d = distutils.core.setup( **a

我使用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>
我在安装python时没有将\Scripts目录添加到PATH中发现错误报告,因此我应用了该通知单中描述的解决方法(即将C:\Python25\Scripts添加到PATH)

这是不是在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包含的所有自定义设置,会有一个更好的答案。

windows使用文件的扩展名来确定它将如何运行

将文件命名为
plugh.py
,并在提示符下使用
plugh.py
调用它

  • 如果使用,它将在安装期间将
    C:\PythonXY\Scripts
    目录添加到
    %PATH%
    (ActivePython 2.6在
    %APPDATA%\Python\Scripts
    中添加了
    %PATH%

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


  • 如果希望用户单击
    .py
    文件,可以将
    .py
    文件与pythonw.exe而不是python.exe相关联,这样终端就不会保持打开状态:顺便说一句,如果只需要将所有批处理输入传递给pyhton脚本,参数序列%1%2%3%4%5%6%7%8%9可以替换为%*(或任何其他可执行文件)。
    @echo off
    c:\python25\python.exec c:\python25\scripts\plugh %1 %2 %3 %4 %5 %6 %7 %8 %9