简体   繁体   English

如何提高 python exe 文件的速度?

[英]How to improve the speed of python exe file?

I am using pyinstaller to generate an exe file for my python script.我正在使用 pyinstaller 为我的 python 脚本生成一个 exe 文件。 When I run my exe file, it takes about 15 seconds to show my output.当我运行我的 exe 文件时,大约需要 15 秒才能显示我的 output。 How can i reduce this time?我怎样才能减少这个时间?

EXE file size is 26 mb. EXE 文件大小为 26 MB。 Any suggestions for reducing my exe file size would also be helpful.任何减少我的 exe 文件大小的建议也会有所帮助。

This is my python script这是我的 python 脚本

import pandas as pd
import datetime
print(datetime.datetime.now())
df = pd.read_excel("D:\sample.xlsx")
print(df)

I create the exe of my script using pyinstaller, like so:我使用 pyinstaller 创建脚本的 exe,如下所示:

pyinstaller --exclude tkinter -F sampleProject.py

How can i reduce this time?我怎样才能减少这个时间?

Simply put: don't use PyInstaller , or use an SSD.简单地说:不要使用PyInstaller ,或者使用 SSD。 A pyinstaller program has to do a lot of extra work before it can run your script. pyinstaller 程序必须做很多额外的工作才能运行您的脚本。

Every time you run it , it creates a temporary directory where it unpacks the executable.每次运行它时,它都会创建一个临时目录,用于解压可执行文件。 This means unpacking Python, its shared libraries and whatever modules you used.这意味着解压缩 Python、它的共享库和您使用的任何模块。 Only after than has happened can it start Python and have it load your program.只有在发生之后,它才能启动 Python 并让它加载您的程序。

A compounding problem is that compared to eg Linux, ms-windows filesystem I/O is slow .一个复杂的问题是,与例如 Linux 相比,ms-windows 文件系统 I/O 很

EXE file size is 26 mb. EXE 文件大小为 26 MB。 Any suggestions for reducing my exe file size would also be helpful.任何减少我的 exe 文件大小的建议也会有所帮助。

Again, this is because a copy of Python, its libraries and all required modules such as pandas is contained in this executable.同样,这是因为 Python、其库和所有必需模块(例如 pandas)的副本包含在此可执行文件中。 On my system, the installed versions of Python 3.7 and Pandas use 160 MiB of disk space.在我的系统上,安装的 Python 3.7 和 Pandas 版本使用 160 MiB 的磁盘空间。 So 26 MiB isn't that bad, really.所以 26 MiB 并不是那么糟糕,真的。

Using PyInstaller only makes sense if you want to distribute one python program to other ms-windows users.仅当您想将一个python 程序分发给其他 ms-windows 用户时,使用PyInstaller才有意义。 (UNIX-like systems generally have Python easily available via their package manager.) If they are using multiple Python program it's probably more efficient to just install Python on their machine. (UNIX-like systems generally have Python easily available via their package manager.) If they are using multiple Python program it's probably more efficient to just install Python on their machine. That will greatly reduce size and startup time of the programs.这将大大减少程序的大小和启动时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM