简体   繁体   English

如果我的脚本包含从 .py 模块导入,Pyinstaller 不会生成 .exe 文件

[英]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.

相关问题 如何从 PyInstaller .exe 恢复 .py 文件? - How to recover a .py file from PyInstaller .exe? 使用 pyinstaller 将 .py 转换为 .exe 后缺少模块 - missing modules after converting .py to .exe with pyinstaller 我的exe 从 pyinstaller 创建的文件不像它是 .py 时那样工作(Pyexcel 问题) - My exe. file created from pyinstaller doesn't work like it does when it was .py (Pyexcel problem) 尝试使用Pyinstaller从.py脚本制作.exe时出现运行时错误 - Runtime error when trying to make a .exe from .py script with Pyinstaller PyInstaller 从 .py 转换为 .exe 时执行脚本失败 - PyInstaller Failed to execute script while converting from .py to .exe 无法将我的 py 文件转换为 exe(尝试了 auto-py-to-exe 和 pyinstaller) - Unable to convert my py file to exe (tried auto-py-to-exe and pyinstaller) 使用PyInstaller将.py转换为.exe时,如何修复丢失模块的问题? - How to fix my problem with missing modules when converting .py to .exe with PyInstaller? 当我的脚本导入模块 pikepdf 和 pdfminer3 时,如何修复 pyinstaller 'no module named...' 错误? - How to fix a pyinstaller 'no module named…' error when my script imports the modules pikepdf and pdfminer3? Python脚本可执行文件与py2exe或pyinstaller - Python script executable with py2exe or pyinstaller 在 pyinstaller 中添加 pip 库以为我的脚本创建 exe 文件 - Adding pip libraries in pyinstaller to create an exe file for my script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM