4

I'm trying to get WSH to run Python .pys scripts and I'm hitting a wall - I've tried this on two machines now, W7x64 and Server2012, same result both time, cscript always comes back with:

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

Procedure (all happening under local admin account):

  1. Installed Python 3.5.1 (x86)
  2. Installed Pywin32 (x86) from Mark Hammond's sourceforge
  3. Ran \site-packages\win32comext\axscript\client\pyscript.py, which returns 'Registered: Python'
  4. Check registry/HKCR - lots of references to pys and python, as expected
  5. Try to run >cscript hello.pys get

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

Any clues? I don't really want to use ActivePython.

4
  • You need a scripting engine installed. That is what ActiveState do. I don't know of any others.
    – Peter Wood
    Jan 27, 2016 at 10:51
  • Also, see community.activestate.com/node/7319 and the suggestion in the answer.
    – Peter Wood
    Jan 27, 2016 at 10:52
  • 1
    @PeterWood thanks but I'm not aware that ActivePython is mandatory - I believe the script engine is actually provided by pywin32 (aka Python for Windows Extensions), which means I've followed the instructions at community.activestate.com/node/7319 already to no avail
    – gh0st
    Jan 27, 2016 at 11:55
  • 1
    Make sure you use the 32bit version of cscript with the 32 bit (x86) python. ie: c:\Windows\SysWOW64\cscript.exe. Looks like you used the default which is 64 bit on a 64 bit version of Windows.
    – patthoyts
    Mar 31, 2018 at 20:21

2 Answers 2

1

It appears that python on Windows is a PITA. So, I had your problem as well, I followed the following steps:

  1. Download Python from python.org. (you probably already have that)
  2. Download PyWin32 from SourceForge.
  3. Download SetupTools from python.org.
  4. On your desktop or in the Start menu, right-click on My Computer then click Properties.
  5. In the Advanced tab, click Environment Variables.
  6. In the System Variables at the bottom, locate the PATH variable and double-click on it.
  7. Add C:\Python27\ and C:\Python27\scripts at the end of the Variable Value box (assuming you installed python in the location C:\Python27).
  8. Click OK in all the dialogs.

It still did not work for me, however, I was puzzled by <python_install>\scripts and found pywin32_postinstall.py in there, running that did the trick!

  1. Execute \scripts\pywin32_postinstall.py
  2. I kept getting the following trace:

    Debugging extensions (axdebug) module does not exist - debugging is disabled..

I traced it to Lib\site-packages\win32comext\axscript\client\framework.py and commented out the trace call that printed that message ... all good.

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)
0

The original answer posted by @thecarpy has good information. There is one more thing to add. If you have multiple versions of Python installed, you need to make sure that the one which matches the version you have registered as the scripting engine is the first python.exe found in your search path. So putting it at the end of the path (as recommended in the previous answer) might not always work. I had a little more hair before I figured this out. 😅

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.