Podbc + Pyinstaller问题pyodbc.InterfaceError IM002

时间:2019-05-02 14:01:49

标签: python-3.x pyinstaller pyodbc

我知道这里有类似的东西,但是尽管遵循了先前线程的建议,但我仍然遇到同样的问题。 我在Pycharm中运行了这段代码,效果很好。

import pyodbc
import pandas
import os
import sys

try:
    currdir = os.path.abspath(__file__)
except NameError:  
     import sys
currdir = os.path.abspath(os.path.dirname(sys.argv[0]))
DBfile = os.path.join(currdir, 'UNION.accdb')
cnxn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=%s;' %DBfile)
sql = "Select * FROM topivot"
df = pandas.read_sql(sql,cnxn)

print(df)

然后我运行命令pyinstaller --onefile pydbb.py,它给了我RuntimeError: maximum recursion depth exceeded while calling a Python object错误。因此,我通过pyi-Makespec --onefile pydbb.py创建了.spec文件,然后运行pyinstaller --onefile pyddb.spec

.spec文件如下所示

# -*- mode: python ; coding: utf-8 -*-
import sys
sys.setrecursionlimit(5000)

block_cipher = None 


a = Analysis(['pyddb2.py'],
         pathex= 
['C:\\Users\\xxxxxx\\AppData\\Local\\Programs\\Python\\Python37-32'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      [],
      name='pyddb2',
      debug=False,
      bootloader_ignore_signals=False,
      strip=False,
      upx=True,
      runtime_tmpdir=None,
      console=True )

此操作成功创建了文件(365MB!),但出现错误:

Traceback (most recent call last): File "pyddb2.py", line 12, in <module> 
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified (0) 
(SQLDriverConnect)') [10948] Failed to execute script pyddb2 

有什么想法吗?

0 个答案:

没有答案