[英]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.我正在尝试使用 pyinstaller 从我的 .py 脚本生成一个 .exe 文件,但经过多次尝试后我意识到它仅在排除某些导入时才有效:它适用于文件具有 .pyi 扩展名的库,而它没有如果我从扩展名为 .py 的文件中导入模块,则不会生成 .exe 文件。 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.这样,第二组注释掉后,我就可以让 pyinstaller 工作,但显然该应用程序在我运行时会返回错误。 If I uncomment them, though, pyinstaller doesn't generate any .exe at all.
但是,如果我取消注释它们,pyinstaller 根本不会生成任何 .exe。
I tried using --hidden-import and other options of pyinstaller, but nothing seems to work, has anyone else experienced a similar problem?我尝试使用 --hidden-import 和 pyinstaller 的其他选项,但似乎没有任何效果,有没有其他人遇到过类似的问题?
I am using Windows, Python3.8, pyinstaller3.6 and developing on Spyder3, if this is of any relevance.我正在使用 Windows、Python3.8、pyinstaller3.6 并在 Spyder3 上开发,如果这有任何相关性的话。
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.
显然,只要我在 Spyder 中运行它就可以正常工作,但是在尝试使用命令提示符时却搞砸了。 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).
一旦解决了这个问题(感谢此线程中的答案),我就设法创建了一个运行良好的 .exe 文件(尽管仍然在上传图像方面苦苦挣扎)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.