0

I have python script that have different modules like : MYSQLdb

(update.py) Python Script:

   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

and i ve created setup.py:

from distutils.core import setup
import py2exe

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

and here is the python command to convert the script to exe:

python setup.py py2exe

and this command cause to this error : enter image description here

how to solve this problem?

1 Answers1

1

I've had this issue where my __init__.py was actually on a bad sector/corrupted. Have you tried recreating this file? (regardless of if the script runs normally as a py)

try:

pip uninstall MySQLdb

followed by:

pip install MySQLdb

--

Script compiles and runs OK as a py?

Please ensure you are running the command prompt as an ADMINISTRATOR as well. start - type cmd - right click - run as administrator

--

At this point, I would reinstall MySQLdb from : http://sourceforge.net/projects/mysql-python/ taking the newest version for your architecture.

Have you tried other MySQL modules? same issue?

Two-Bit Alchemist
  • 17,966
  • 6
  • 47
  • 82
  • pip uninstall MySQLdb, then pip install MySQLdb (seems like a corrupted file) -- script runs ok on it's own? – Justin Tokarchuk Feb 20 '15 at 16:15
  • yea it runs correctly without any single error as script.py,but i dont know anything about pip command ??? and when i execute the pip command , its not knows as internal command ??? –  Feb 20 '15 at 16:43
  • are you running the command prompt as an **administrator** ? The screenshot suggest you either have UAC off or you are not. also, is that the entire script? if so, it suggests that there is no way to actually populate the variables with information, which is why the compiler might be erroring out. (ie do you have a __ main __ function that takes arguments? are you getting data via some type of input? – Justin Tokarchuk Feb 20 '15 at 16:49
  • yea i am running the command prompt as administrator ,and its not the entire script ,its part of it ,because the error results for MYSQLdb.so i post the mysqlDB code part so ,and i have raw_input in the entire script , –  Feb 20 '15 at 17:16
  • by the way i run setup script with simple python script without importing any external modules ,and its worked gr8,but the problem with the external modules in python , like MYSQLdb –  Feb 20 '15 at 17:18
  • where did you get MySQLdb from? Have you tried reinstalling it using whatever method you got it by? (i had assumed pip, but apparently not) – Justin Tokarchuk Feb 20 '15 at 17:38
  • have you tried reinstalling it? Have you used other modules without error? since it's referencing the init script of the module you are using, logic dictates that there's a problem in there. – Justin Tokarchuk Feb 20 '15 at 17:59