Home > Software engineering >  Why I am getting ModuleNotFoundError when I make an Exe file for tkinter GUI?
Why I am getting ModuleNotFoundError when I make an Exe file for tkinter GUI?

Time:04-04

I have a simple code to use the LHS design of the experiment, and it works fine.

from tkinter import *
from pyDOE import *

root = Tk()
root.geometry("400x400")

n_points = IntVar()
n_features = IntVar()

label1 = Label(root, text="Initial No. sample points:")
label1.grid(row=0, column=0)

entry1 = Entry(root, textvariable=n_points)
entry1.grid(row=0, column=1)

label2 = Label(root, text="No. parameters:")
label2.grid(row=1, column=0)

entry2 = Entry(root, textvariable=n_features)
entry2.grid(row=1, column=1)

label3 = Label(root)
label3.grid(row=3, column=0, columnspan=2)

def LHS():
    lhs_design = lhs(n_features.get(), samples=n_points.get(), criterion="corr")
    label3.config(text="your design is:"   str(lhs_design))

mybutton = Button(root, text="Calculate!", command=LHS)
mybutton.grid(row=2, column=0, columnspan=2)

root.mainloop()

I want to create an Exe file using pyinstaller. I follow these steps:

  1. put mycode.py in a folder.
  2. open cmd, and I change the directory to the folder
  3. run pyinstaller --onefile -w mycode.py
  4. Then in the created dist folder, there would be an Exe file

however, when I run the exe file, I get this error:

Traceback (most recent call last):
  File "mycode.py", line 2, in <module>
ModuleNotFoundError: No module named 'pyDOE'

Am I making a mistake somewhere in the code that I have run in cmd? or do I need to add the pyDOE package somewhere in the exe file folder?

I also had the same problem in another post: How to make an executable file when we are running an R script in python and Tkinter?

I was trying to run an r code in python, so I added this library: from rpy2.robjects.packages import importr, and I got similar error. I thaught, the error might be because of reading from r but it seems I am making a mistake somewhere else.

CodePudding user response:

I found the answer for my post.

It seems it makes difference where to put mycode.py file and using the pyinstaller.

The file needs to be where your python is installed, in the scripts folder. Then, we can use pyinstaller mycode.py.

  • Related