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.

4

1 回答 1

0

是的,您必须单独安装该库。事实上,如果您访问SourceForge 页面,您会看到有一个完全不同的二进制文件可用于 2.7。如果您使用 32 位 Python,则需要pywin32-218.win32-py2.7.exe ;如果您使用 64 位 Python,则需要 pywin32-218.win-amd64-py2.7.exe

您可以通过 GUI 界面安装它(当您尝试执行文件时会出现),或者您可以在命令行上调用 easy_install(如果您安装了 setuptools 或分发安装):

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

如果您想在使用virutalenv创建的虚拟环境中安装库,则使用 easy_install 是唯一的方法。

于 2013-05-17T00:58:40.840 回答