我有一个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 "PyInstallerloaderpyimod03_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_projectticketingingenieriavenvlibsite-packagessetuptoolsdistutils_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"
编辑:包含clidriver目录到pyinstaller命令:
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
- Auto-py-to-exe: 2.9.0 操作系统:Windows 10 Pro 21H1 (SO compilation 19043.1165)
最后我得到了解决方案,我必须直接将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"