gh0st
gh0st

Reputation: 87

Cannot get python scripting working under WSH

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.

Upvotes: 4

Views: 2091

Answers (2)

Bob Kline
Bob Kline

Reputation: 338

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. 😅

Upvotes: 0

thecarpy
thecarpy

Reputation: 900

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)

Upvotes: 1

Related Questions