简体   繁体   中英

Pyinstaller not generating .exe file if my script contains imports from .py modules

I'm trying to generate an .exe file from my .py script using pyinstaller, but I realised after several attempts that it only works when I exclude certain imports: it works fine with libraries whose files have .pyi extensions, while it doesn't generate the .exe file if I import modules from files with .py extensions. For instance:

#### These are fine because .pyi
import tkinter as tk
from tkinter import messagebox
from threading import Thread
import decimal as dec
import math

#### These don't let Pyinstaller generate an .exe --> Most likely because these are .py files, as opposed to .pyi!!
# from PIL import ImageTk, Image
# import numpy as np
# import matplotlib.pyplot as plt
# from mpl_toolkits.mplot3d import axes3d
# from matplotlib import style
# from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

This way, with the second group commented out, I get pyinstaller to work, but obviously the app returns errors when I run it. If I uncomment them, though, pyinstaller doesn't generate any .exe at all.

I tried using --hidden-import and other options of pyinstaller, but nothing seems to work, has anyone else experienced a similar problem?

I am using Windows, Python3.8, pyinstaller3.6 and developing on Spyder3, if this is of any relevance.

Thank you in advance to anyone who will answer!

Thanks to all those who tried to answer, I finally sorted this thing out and it was much trickier than I thought, as the problem wasn't in my code or in the modules, but in the configuration of my environment. I had basically forgotten to activate the base environment. Obviously it worked fine as long as I ran it in Spyder, but messed it up when trying to use the command prompt. Once fixed this (thank to the answers in this thread ) I managed to create an .exe file that runs just fine (although still struggling with uploading images).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM