0

I have a program here that I would like to convert to 2.7. This code works well in Python 3.x, however, for my needs it must be 2.7. Could someone 'convert' this to python 2.7 for me? I have heard of a 3to2.py tool but I do know how to get/use it. Anyway, here is the code I have for 3.3.

def compiler(program):
    import os, win32com.client, time
    os.startfile("C:\\Windows\\System32\\cmd.exe")
    time.sleep(2)
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.AppActivate('C:\\Windows\\System32\\cmd.exe')
    setup(program)
    shell.SendKeys("py MyCompiling.py.setup("+program+") py2exe\n")

def setup(program):
    from distutils.core import setup
    import py2exe
    setup(console=[program + ".py"])

compiler('test1')

EDIT: When I try to run I get

ImportError: No module named win32com.client

Do I have to install this module seperately? If so, could someone please post the link.

Ulsting
  • 491
  • 2
  • 6
  • 17
  • What exactly fails under python2.7? At a quick glance, I don't see any reason why this wouldn't work unless something in `win32com.client` fails under python2.7 ... – mgilson May 16 '13 at 23:15
  • 1
    win32com.client works fine in 2.7 i think its the `setup(program)` – Serial May 16 '13 at 23:17
  • This code contains *NO* Python3-isms AFAICS. If you are having trouble running it under Python 2.7, it's probably because of missing modules (such as win32com, which [appears to be a separately-installable module.](http://stackoverflow.com/questions/14913607/how-to-install-win32com-module-in-a-virtualenv)). Be aware that modules in 3.x and 2.7 are entirely separate: installing a module in 3.x won't make it available in 2.7, and vice versa. – kampu May 17 '13 at 02:15

1 Answers1

0

Yes, you must install the library separately. In fact, if you visit the SourceForge page, you will see that there is an entirely different binary available for 2.7. You will want pywin32-218.win32-py2.7.exe if you are using 32-bit Python or pywin32-218.win-amd64-py2.7.exe if you are using 64-bit Python.

You can install it via the GUI interface (which comes up when you try to execute the file), or you can call easy_install on it (if you have setuptools or distribute installed) at the command line:

C:\> C:\Python27\Scripts\easy_install pywin32-218.win32-py2.7.exe

Using easy_install is the only way if you want to install the library in a virtual environment created with virutalenv.

jpmc26
  • 28,463
  • 14
  • 94
  • 146