使用py2exe将python脚本转换为windows 7 32bit中的exe

时间:2015-02-20 16:06:00

标签: python-2.7 exe mysql-python py2exe

我的python脚本有不同的模块,如:MYSQLdb

(适用update.py) Python脚本

   import fileinput
    import sys
    import os
    import re
    import subprocess
    import MySQLdb


#############################################################################
# **DB Functions:::

def fetch_pn (host,username,password,db_name):
    # Open database connection
    db = MySQLdb.connect(host,username,password,db_name)

    # prepare a cursor object using cursor() method
    cursor = db.cursor()

    # execute SQL query using execute() method.
    sql_pickupNum="SELECT * from orderNO"
    cursor.execute(sql_pickupNum)
    # Fetch a single row using fetchone() method.
    data = cursor.fetchone()
    #print "pickup number in mainDB : %s " % data
    pn_DB=data
    return pn_DB

    try:     
       # Commit your changes in the database
       db.commit()
    except:
       # Rollback in case there is any error
       db.rollback()

    # disconnect from server
    db.close()





mainDB_pn=fetch_pn("localhost","username","password","DB1")
secondDB_pn=fetch_pn("localhost","username","password","DB2")
#############################################################################   

ask=raw_input("Enter 1 for main DB or 2 for second DB ???")

if int(ask)==2 :
    print "the old value now in mainDB_pn :%s"%secondDB_pn
    print"Converting to secondDB"
    update_pn("localhost","username","password","DB2",mainDB_pn)
    print "The new value of secondDB_PN =%s"%mainDB_pn

elif int(ask)==1:
    print "the old value now in mainDB_pn :%s"%mainDB_pn
    print"Converting to mainDB"
    update_pn("localhost","username","password","DB1",secondDB_pn)
    print "The new value of mainDB_PN =%s"%secondDB_pn

我创建了 setup.py

from distutils.core import setup
import py2exe

setup(console=['update.py'])

这里是将脚本转换为exe的python命令:

python setup.py py2exe

并且此命令导致此错误: enter image description here

如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

我遇到过这个问题,我的__init__.py实际上处于坏扇区/损坏状态。你试过重新创建这个文件吗? (无论脚本是否正常运行为py)

尝试:

pip uninstall MySQLdb

接下来是:

pip install MySQLdb

-

脚本编译并运行OK作为py?

请确保您也以管理员身份运行命令提示符。开始 - 键入cmd - 右键单击​​ - 以管理员身份运行

-

此时,我将从http://sourceforge.net/projects/mysql-python/重新安装MySQLdb,为您的架构提供最新版本。

您是否尝试过其他MySQL模块?同样的问题?

答案 1 :(得分:-2)

当我重新安装MySQLdb作为MSI安装程序时,它成功了 所以问题现在解决了......