Exe made Python program run full disk Temp

Copyright: no copyright, reprint free to https://blog.csdn.net/MAOZEXIJR/article/details/91044472

First, how to turn Python exe

1, the installation pyinstaller

pip insatll pyinstaller

2, pyinstaller

(1) packaged into folders

pyinstaller -D xx.py

(2) packaged into file

pyinstaller -F xx.py

(3) third-party libraries (e.g. PyQt5) when packaging

pyinstaller --paths 库路径 -F -w xx.py

 

Second, the warehouse explosion cause and solutions

1, a phenomenon

Xx.exe found after frequent calls into disk folder C: \ Windows \ Temp or  C: \ Users username AppData \ Local \ \ \ Temp generated under a large number of named _MEIxxxx file folder, disk almost full

 

2, reason

Pyinstaller pseudo-official description is as follows:

"Official" link: https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html

 

3, to solve

(1) a Scheme

Method: Specify warehouse explosion path, avoiding not automatically delete permissions shortage caused

Advantages: Get peace of mind

Disadvantages: unstable, packed instruction complicated point

pyinstaller --runtime-tmpdir 指定爆仓路径 -F xx.py

 

(2) Scheme II

Method: dynamic access to the currently running program used _MEIxxxx  path, after a run os.remove

Benefits: stable fly

Cons: write code

# !/usr/bin/python3
# coding: utf-8
import gc
import os
import sys
import traceback

this = os.path.abspath(os.path.dirname(__file__))
module = os.path.split(this)[0]
print('sys.path.append("%s")' % module)
sys.path.append(module)
for i, val in enumerate(sys.path):
    print("[%s] %s" % (i + 1, val))


def delMEI():
    for index, path in enumerate(sys.path):
        basename = os.path.basename(path)
        if not basename.startswith("_MEI"):
            continue

        drive = os.path.splitdrive(path)[0]
        if "" == drive:
            path = os.getcwd() + "\\" + path
            path = path.replace("\\\\", "\\")

        if os.path.isdir(path):
            try:
                print("remove", path)
                os.remove(path)
            except:
                pass
            finally:
                break


if __name__ == '__main__':
    try:
        print("Start to xx..")
        # do something
        print("End of the xx")
    except:
        traceback.print_exc()
    finally:
        gc.collect()
        delMEI()

 

Guess you like

Origin blog.csdn.net/MAOZEXIJR/article/details/91044472