【问题记录】python的py文件生成exe可执行程序闪退
今天想弄一下這個,記錄一下過程:
1.
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
pyinstaller vei.py
執(zhí)行這個之后生成了build目錄和exe文件,但發(fā)現exe存在閃退問題:
查了一下說缺少相關包,繼續(xù)下載:
pip install pypiwin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo下載相關包復制到當前項目下:
pip install pycairo-1.20.0-cp39-cp39-win_amd64.whl
pip install PyQt5
pip install IPython
pip install wxPython
pip install ipykernel
pip install zmq
一些七七八八的包,也不知道干什么用的,查到有文章說要下載這些包。
然后在命令行輸入pyinstaller 說不是可執(zhí)行程序,于是在命令行全局安裝 pip intall pyinstaller
用參數-F 這樣dist下面只有exe文件
報錯信息顯示PIL模塊找不到,于是:安裝PIL顯示失敗,于是安裝pillow
C:\Windows\system32>pip install PIL
ERROR: Could not find a version that satisfies the requirement PIL
ERROR: No matching distribution found for PIL
C:\Windows\system32>pip install Pillow
Collecting Pillow
Using cached Pillow-8.1.1-cp39-cp39-win_amd64.whl (2.2 MB)
Installing collected packages: Pillow
Successfully installed Pillow-8.1.1
不知道執(zhí)行這個exe還是顯示模塊找不到,于是重新寫了一個py文件再次打包:
已經可以執(zhí)行了。說明運行exe成功。
另外運行一段修改png為jpg的拒絕訪問問題:
import osfrom PIL import Image import cv2 as cv def PNG_JPG(PngPath):img = cv.imread(PngPath, 0)w, h = img.shape[::-1]infile = PngPathoutfile = os.path.splitext(infile)[0] + ".jpg"img = Image.open(infile)img = img.resize((int(w / 2), int(h / 2)), Image.ANTIALIAS)try:if len(img.split()) == 4:# prevent IOError: cannot write mode RGBA as BMPr, g, b, a = img.split()img = Image.merge("RGB", (r, g, b))img.convert('RGB').save(outfile, quality=70)os.remove(PngPath)else:img.convert('RGB').save(outfile, quality=70)os.remove(PngPath)return outfileexcept Exception as e:print("PNG轉換JPG 錯誤", e)path_root = os.getcwd() Path= 'C:\\Users\\pic\\' img_dir = os.listdir(Path) for img in img_dir:if img.endswith('.png'):PngPath= Path + imgPNG_JPG(PngPath) img_dir = os.listdir(Path) for img in img_dir:print(img)一開始一直報錯顯示permission denied
方法:用管理員身份運行pycharm就好了
再次打開文件,后綴已經修改。
總結
以上是生活随笔為你收集整理的【问题记录】python的py文件生成exe可执行程序闪退的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【链表】链表变化时其中的节点变化情况
- 下一篇: 【笔记】springboot使用Spri