【发布时间】:2021-01-26 18:29:58
【问题描述】:
我正在尝试使用 pyinstaller 在 Windows 中创建可执行文件,但如果我导入 Pmw,则在运行可执行文件时会出错。
我正在使用以下代码来创建示例 GUI
import tkinter as tk
from tkinter import ttk
import Pmw
class Test():
def __init__(self):
self.mainwindow = tk.Tk()
self.mainwindow.title("Main Window")
self.mainwindow.geometry("600x300")
self.mainwindow.configure(background='light sea green')
self.textInfo = tk.Text(self.mainwindow, width=60, height=30)
self.textInfo.pack(side=tk.TOP)
self.labelWelcome = ttk.Label(self.mainwindow, text="Welcome to the Ribadesella Guest House Platform!")
self.labelWelcome.place(x = 160, y = 80, width = 280, height = 30)
self.buttonHello = ttk.Button(self.mainwindow, text="Hello", command=self.hello)
self.textHello = tk.Text(self.mainwindow)
self.buttonHello.place(x = 80, y = 200, width = 150, height = 35)
self.textHello.place(x = 230, y = 200, width = 150, height = 35)
self.mainwindow.mainloop()
def hello(self):
self.textHello.insert(tk.END,'Hello world')
start = Test()
如果我省略 import Pmw 行,它编译并运行良好,但如果我包含它,我会收到错误:
Traceback (most recent call last):
File "test.py", line 10, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "c:\anaconda3\lib\site-packages\Pmw\__init__.py", line 34, in <module>
_loader = 'Pmw.' + _instdirs[0] + '.lib.PmwLoader'
IndexError: list index out of range
我知道它与包惰性导入器有关,但我不知道如何修复它(或者惰性导入器是什么)
更多细节如下:
- 我还没有在代码中包含
Pmv的使用,但我以后会这样做。 - 我直接在python中运行
.py时没有出现错误 -
Pmw版本2.0.1 -
pyinstaller版本4.2 -
Python版本3.6.5 - 创建我正在使用的可执行文件:
pyinstaller --onefile --debug=all test.py
【问题讨论】:
标签: python pyinstaller pmw