【问题标题】:Cannot get python scripting working under WSH无法在 WSH 下运行 python 脚本
【发布时间】:2016-01-27 10:33:06
【问题描述】:

我正在尝试让 WSH 运行 Python .pys 脚本,但我碰壁了 - 我现在已经在 W7x64 和 Server2012 两台机器上尝试过这个,两次结果相同,cscript 总是返回:

CScript Error: Can't find script engine "Python"

过程(所有在本地管理员帐户下发生):

  1. 已安装 Python 3.5.1 (x86)
  2. 从 Mark Hammond 的 sourceforge 安装了 Pywin32 (x86)
  3. 运行\site-packages\win32comext\axscript\client\pyscript.py,返回'Registered: Python'
  4. 检查注册表/HKCR - 大量引用 pys 和 python,正如预期的那样
  5. 尝试运行>cscript hello.pys get

    CScript 错误:找不到脚本引擎“Python”

有什么线索吗?我真的不想使用 ActivePython。

【问题讨论】:

  • 您需要安装脚本引擎。这就是 ActiveState 所做的。我不知道其他人。
  • 另外,请参阅community.activestate.com/node/7319 和答案中的建议。
  • @PeterWood 谢谢,但我不知道 ActivePython 是强制性的 - 我相信脚本引擎实际上是由 pywin32(又名 Python for Windows Extensions)提供的,这意味着我已经按照@处的说明进行操作987654322@已经无济于事了
  • 确保使用 32 位版本的 cscript 和 32 位 (x86) python。即:c:\Windows\SysWOW64\cscript.exe。看起来您在 64 位版本的 Windows 上使用了默认的 64 位。

标签: python pywin32 wsh


【解决方案1】:

Windows 上的 python 似乎是一个 PITA。所以,我也遇到了你的问题,我关注了以下steps

  1. python.org 下载 Python。 (你可能已经有 那)
  2. 从 SourceForge 下载 PyWin32
  3. 从 python.org 下载SetupTools
  4. 在桌面或“开始”菜单中,右键单击“我的电脑”,然后单击“属性”。
  5. 在“高级”选项卡中,单击“环境变量”。
  6. 在底部的系统变量中,找到 PATH 变量并双击它。
  7. 在变量值框的末尾添加C:\Python27\C:\Python27\scripts(假设您将python安装在C:\Python27位置)。
  8. 在所有对话框中单击“确定”。

它仍然对我不起作用,但是,我对<python_install>\scripts 感到困惑,并在其中找到了pywin32_postinstall.py,运行它就可以了!

  1. 执行 \scripts\pywin32_postinstall.py
  2. 我不断得到以下跟踪:

    调试扩展 (axdebug) 模块不存在 - 调试被禁用..

我将 traced 发送到 Lib\site-packages\win32comext\axscript\client\framework.py 并注释掉了打印该消息的 trace 调用......一切都很好。

C:\Users\jdoe>type  d:\python2vbs.wsf
<?XML Version="1.0" encoding="ISO-8859-1"?>
<?job error="true" debug="false"?>
<package>
        <job>

        <script language="VBScript">
        <![CDATA[
public sub vbsOutput(strText)
        wscript.echo strText & " (from vbsOutput)"
end sub
        ]]>
        </script>

        <script language="Python">
        <![CDATA[
import sys
globals.vbsOutput('python testing')
        ]]>
        </script>

        </job>
</package>

C:\Users\jdoe>cscript  d:\python2vbs.wsf
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.

python testing (from vbsOutput)

【讨论】:

    猜你喜欢
    • 2015-11-30
    • 2013-01-24
    • 2016-03-06
    • 2017-12-25
    • 2020-09-22
    • 2018-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多