pyinstaller modulenotfound错误:没有模块名称'mysql'

时间:2019-04-02 20:33:24

标签: python-3.x pyinstaller mysql-python

我使用pyinstaller创建了一个可执行文件。我的脚本都运行良好,但是当我运行可执行文件时,出现以下错误。看起来它不喜欢DBconnection.py中的mysql连接器。任何帮助表示赞赏。

回溯(最近通话最近):   文件“ main.py”,第8行   文件“ c:\ programdata \ anaconda3 \ lib \ site-packages \ PyInstaller \ loader \ pyimod03_i exec_module中的mporters.py“,第631行   文件“ DBconnection.py”,第2行,在 ModuleNotFoundError:没有名为“ mysql”的模块 [4780]无法执行脚本主程序

DBconnection.py:

from configparser import ConfigParser
from mysql.connector import MySQLConnection
import Global

def create_db_connection(filename= 'my.ini', section= 'dbconnection'):
parser = ConfigParser()
parser.read(filename)

db = {}
if parser.has_section(section):
    items = parser.items(section)
    for item in items:
        db[item[0]] = item[1]

else:
    raise Exception('{0} not found in the {1} file'.format(section. filename))

#global conn
Global.conn = MySQLConnection(**db)
print(Global.conn)


def close_db_connection():
Global.conn.close()

main.py:

from servers import updateservers
from policies import updatepolicies
from updateguardpoints import updateguardpoints
from activities import updateactivities
from guardpointstatus import updateguardpointstatus
from application import updateapplication
from application_servers import updateapplication_servers
from DBconnection import create_db_connection
from DBconnection import close_db_connection
from TrouxConnection import TrouxConnection
from TrouxConnection import CloseTrouxConnection
import Global


create_db_connection()
TrouxConnection()
updateservers()
updatepolicies()
updateguardpoints()
updateactivities()
updateguardpointstatus()
updateapplication()
updateapplication_servers()
CloseTrouxConnection()
close_db_connection()

1 个答案:

答案 0 :(得分:0)

重新安装了mysql-使用PIP的连接器。问题已解决