【问题记录】python的py文件生成exe可执行程序闪退
今天想弄一下這個(gè),記錄一下過(guò)程:
1.
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
pyinstaller vei.py
執(zhí)行這個(gè)之后生成了build目錄和exe文件,但發(fā)現(xiàn)exe存在閃退問(wèn)題:
查了一下說(shuō)缺少相關(guān)包,繼續(xù)下載:
pip install pypiwin32 -i https://pypi.tuna.tsinghua.edu.cn/simple
https://www.lfd.uci.edu/~gohlke/pythonlibs/#pycairo下載相關(guān)包復(fù)制到當(dāng)前項(xiàng)目下:
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
一些七七八八的包,也不知道干什么用的,查到有文章說(shuō)要下載這些包。
然后在命令行輸入pyinstaller 說(shuō)不是可執(zhí)行程序,于是在命令行全局安裝 pip intall pyinstaller
用參數(shù)-F 這樣dist下面只有exe文件
報(bào)錯(cuò)信息顯示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í)行這個(gè)exe還是顯示模塊找不到,于是重新寫了一個(gè)py文件再次打包:
已經(jīng)可以執(zhí)行了。說(shuō)明運(yùn)行exe成功。
另外運(yùn)行一段修改png為jpg的拒絕訪問(wèn)問(wèn)題:
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轉(zhuǎn)換JPG 錯(cuò)誤", 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)一開始一直報(bào)錯(cuò)顯示permission denied
方法:用管理員身份運(yùn)行pycharm就好了
再次打開文件,后綴已經(jīng)修改。
總結(jié)
以上是生活随笔為你收集整理的【问题记录】python的py文件生成exe可执行程序闪退的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【链表】链表变化时其中的节点变化情况
- 下一篇: 在集群服务器进行自定义数据集训练记录过程