无法在WSH下运行python脚本

2024-09-28 22:33:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试让WSH运行Python.pys脚本,但我遇到了一个问题-我已经在两台机器上尝试过了,W7x64和Server2012,两台机器的结果都一样,cscript总是返回:

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

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

  1. 已安装Python3.5.1(x86)
  2. 从markhammond的sourceforge安装Pywin32(x86)
  3. 运行\site packages\win32comext\axscript\client\pyscript.py,返回'Registered: Python'
  4. 检查registry/HKCR-pys和python的大量引用
  5. 尝试运行>;cscript你好。皮斯得到

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

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


Tags: 程序脚本机器scripterrorfindcanengine
1条回答
网友
1楼 · 发布于 2024-09-28 22:33:17

Windows上的python似乎是一个PITA。所以,我也有你的问题,我遵循以下steps

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

它仍然对我不起作用,然而,我被<python_install>\scripts迷惑了,发现{}在那里,跑起来就成功了!在

  1. 执行\scripts\pywin32_安装后.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)

相关问题 更多 >