Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
701 views
in Technique[技术] by (71.8m points)

Python executable with pyinstaller and Pmw

I am trying to create an executable in windows using pyinstaller, but I get an error when running the executable if I import Pmw.

I am using the following code to create a sample 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()

It compiles and runs well if I omit the line import Pmw, but if I include it, I get the error:

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:anaconda3libsite-packagesPmw\__init__.py", line 34, in <module>
    _loader = 'Pmw.' + _instdirs[0] + '.lib.PmwLoader'
IndexError: list index out of range

I understand it has something to do with the package lazy importer, but I have no clue how to fix it (or what a lazy importer is, for that matter)

A few more details bellow:

  • I have not included the use of Pmv in the code yet, but I will in the future.
  • The error does not appear when I run the .py directly in python
  • Pmw version 2.0.1
  • pyinstaller version 4.2
  • Python version 3.6.5
  • To create the executable I am using: pyinstaller --onefile --debug=all test.py
question from:https://stackoverflow.com/questions/65907149/python-executable-with-pyinstaller-and-pmw

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a working solution here. The link in the answer is not working (that's the reason why I posted this question), but there is a working one in the comments of said answer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...