Mar*_* S. 7 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(
**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的所有自定义,会有比这更好的答案.
如果您使用的ActivePython,它都已经添加C:\PythonXY\Scripts目录到%PATH%(ActivePython的2.6还增加了PEP 370的%APPDATA%\Python\Scripts,以%PATH%在安装过程中).
要在Windows机器上部署脚本,最好使用Distribute,它将负责为脚本安装.exe包装器并调用安装软件包的实际Python(以避免与多个Python安装冲突 - 因此命名脚本结束. py是不够的).有关此主题的更多信息,请阅读Distribute文档中的入口点.
| 归档时间: |
|
| 查看次数: |
3942 次 |
| 最近记录: |