Python轉exe方法與 MEI清除方法

2021-09-24 05:01:56 字數 1534 閱讀 8747

一、如何python轉 exe

1、安裝 pyinstaller

pip insatll pyinstaller
2、使用 pyinstaller

(1)打包成資料夾

pyinstaller -d xx.py
(2)打包成檔案

pyinstaller -f xx.py
(3)打包時引入第三方庫(如pyqt5)

pyinstaller --paths 庫路徑 -f -w xx.py
二、爆倉因果與解決方案

1、現象

頻繁呼叫轉換後的 xx.exe 發現磁碟資料夾 c:\windows\temp

下產生了大量名為_mei***x的資料夾,幾乎要爆滿 磁碟

2、原因

pyinstaller 的偽官方說明如下:

3、解決

(1)方案一

方法:指定爆倉路徑,避免許可權不足引起的無法自動刪

優點:省事省心

缺點:不穩定,打包指令複雜了點

pyinstaller --runtime-tmpdir 指定爆倉路徑 -f xx.py
(2)方案二

方法:動態獲取當前執行程式所使用的_mei***x路徑,執行結束後 os.remove

優點:穩定靠譜

缺點:寫**

# !/usr/bin/python3

# coding: utf-8

# gc.py

import os

import re

import sys

def clear():

for path in sys.path:

if re.match(r'^_mei\d+$', os.path.basename(path)):

if os.path.exists(path):

os.remove(path)

# !/usr/bin/python3

# coding: utf-8

# demo.py

import os

import sys

import traceback

# not using os.path.abspath(__file__)

work_dir = os.path.dirname(os.path.abspath(sys.ar**[0]))

import gc

try:

pass

except:

traceback.print_exc()

finally:

gc.clear()

Window下python轉exe工具

pip install pyinstaller pip install pypiwin32 upx壓縮工具 可不必,只是減少exe體積 放入python安裝目錄 pyinstaller f w i i.ico test.pyw f 生成乙個檔案 d 生成乙個目錄 預設 k 包含tcl tk d de...

python打包exe的方法

cxfreeze,pyinstaller,py2exe三種方式 目前網上能獲取的免費的python打包工具主要有三種 py2exe pyinstaller和cx freeze。其中pyinstaller最新版只支援python2.7,py2exe計畫開發支援python3.x版本,但是目前還沒有完成...

python檔案轉EXE可執行檔案

系統版本 windows7 64位 anaconda版本 虛擬環境python版本 2.7.15 安裝的其他庫函式版本 這裡寫 片直接 pip install pyinstaller就好了。安裝成功後cmd視窗cd到要轉化的py檔案所在目錄,然後命令列執行 pyinstaller f py 成功後當...