如何运行已安装的python脚本?
我使用distutils安装python软件包,使用setup.py:如何运行已安装的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
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%
)如果希望用户单击
.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