1、安装PyInstaller
1)命令行:
pip install PyInstaller
2)Pycharm安装
Setting - Project Interpreter - [+] - 搜索PyInstaller - 点击【Install Package】
2、编译生成exe文件
pyinstaller -F -w main.py
3、生成的dist文件中包含exe文件,点击即可运行
4、问题记录
1)运行pyinstaller -F -w main.py时提示有木马病毒
运行的报错信息
19989 INFO: Copying bootloader EXE to D:\workspace\pycharm\pyqt\guitest\dist\main.exe
20069 INFO: Copying icon to EXE
Traceback (most recent call last):
File "D:\software\python310\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 33, in pywin32error
yield
File "D:\software\python310\lib\site-packages\win32ctypes\pywin32\win32api.py", line 209, in BeginUpdateResource
return _resource._BeginUpdateResource(filename, delete)
File "D:\software\python310\lib\site-packages\win32ctypes\core\cffi\_resource.py", line 114, in _BeginUpdateResource
result = check_null(
File "D:\software\python310\lib\site-packages\win32ctypes\core\cffi\_util.py", line 78, in __call__
self._raise_error(function_name)
File "D:\software\python310\lib\site-packages\win32ctypes\core\cffi\_util.py", line 89, in _raise_error
hdst = win32api.BeginUpdateResource(dstpath, 0)
File "D:\software\python310\lib\site-packages\win32ctypes\pywin32\win32api.py", line 208, in BeginUpdateResource
with _pywin32error():
File "D:\software\python310\lib\contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "D:\software\python310\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (225, '', '无法成功完成操作,因为文件包含病毒或潜在的垃圾软件。')
修改为允许操作
命令解析
-F, --onefile 创建一个文件捆绑可执行文件。
-w, --windowed, --noconsole
Windows和Mac OS X:不提供标准I / O的控制台窗口。在Mac OS X上,这也会触发构建OS X .app捆绑软件。在Windows上,如果第一个脚本是“ .pyw”文件,则将设置此选项。在* NIX系统中,此选项被忽略。