auto-py-to-exe.py文件可以工作,但.exe会弹出一系列错误

fgw7neuy  于 2022-11-07  发布在  DB2
关注(0)|答案(1)|浏览(449)

我有一个Python脚本,我想将其转换为exe。转换实际上给了我一个.exe文件,但当我运行它时,弹出了以下错误:

Traceback (most recent call last):
  File "TicketingIngenieria.py", line 10, in <module>
  File "<frozen importlib._bootstrap>", line 1007, in _find_and load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "ibm_db", line 7, in <module>
  File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 3] System cannot find the specified route: 'C:\\Users\\sromero\\AppData\\Local\\Temp\\_MEI50802\\clidriver\\bin'
[18820] Failed to execute script 'TicketingIngenieria' due to unhandled exception!

当我将文件从.py转换为.exe时,在CMD中看到以下消息:

c:\py_project\ticketingingenieriavenv\lib\site-packages\setuptools\distutils_patch.py:25: UserWarning: Distutils was imported before Setuptools. This usage is discouraged and may exhibit undesirable behaviors or errors. Please use Setuptools' objects directly or at least import Setuptools first.
  warnings.warn(

我不知道该怎么做,我可以猜测是模块相关的,但是用Python执行脚本确实有效,一旦我把它作为可执行文件执行,它就给我这些错误。下面是模块列表:

from tkinter import *
import datetime
from datetime import datetime
from tkinter import ttk
from tkinter import messagebox
from PIL import Image, ImageTk
from pprint import pprint
import pyodbc
import ibm_db
import os

这是我使用的命令:

pyinstaller --noconfirm --onefile --windowed --add-data "G:/09 SCRIPTS AUTOMATIZACION/tst/FLOS.ico;."  "G:/09 SCRIPTS AUTOMATIZACION/tst/TicketingIngenieria.py"

**编辑:**pyinstaller命令中包含clidriver目录:

pyinstaller --noconfirm --onefile --windowed --add-data "G:/09 SCRIPTS AUTOMATIZACION/tst/FLOS.ico;." --add-data "C:/py_project/TicketingIngenieriaVENV/Lib/site-packages/clidriver;clidriver/"  "G:/09 SCRIPTS AUTOMATIZACION/tst/TicketingIngenieria.py"

这会产生以下错误:

ImportError: DLL load failed while importing ibm_db: Could not find the specified module

**编辑:**尝试添加:--add-data "C:/py_project/TicketingIngenieriaVENV/Lib/site-packages/clidriver/bin/amd64.VC12.CRT;./clidriver/"

错误:

FileNotFoundError: [WinError 2] System cannot find the specified file: 'C:\\Users\\sromero\\AppData\\Local\\Temp\\_MEI189962\\clidriver\\bin'

系统版本:

  • Python版本:3.9.4
  • 自动py到exe:2.9.0
  • 手术系统:Windows 10专业版21上半年(SO编译19043.1165)
eoigrqb6

eoigrqb61#

最后我得到了解决方案,我必须直接将ibm_db. dll添加到脚本中。这是对我有效的命令:

pyinstaller --noconfirm --onedir --console --add-data "G:/09 SCRIPTS AUTOMATIZACION/tst/FLOS.ico;." --add-binary "C:/py_project/TicketingIngenieriaVENV/Lib/site-packages/ibm_db_dlls/ibm_db.dll;ibm_db_dlls/" --add-data "C:/py_project/TicketingIngenieriaVENV/Lib/site-packages/clidriver;clidriver/" --paths "C:/py_project/TicketingIngenieriaVENV/Lib/site-packages/clidriver/bin/amd64.VC12.CRT"  "C:/py_project/TicketingIngenieriaVENV/TicketingIngenieria.py"

相关问题