700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > pyqt5使用pyinstaller打包项目为exe

pyqt5使用pyinstaller打包项目为exe

时间:2022-05-25 11:07:24

相关推荐

pyqt5使用pyinstaller打包项目为exe

一、 打包

1. 生成index.spec

pyinstaller -F -w -i logo.ico index.py# 不显示cmdpyinstaller -F -c -i logo.ico index.py# 建议先用-c,这样如果打包不成功的话可以看到哪里有错

-F 指只生成一个exe文件,不生成其他dll文件

-w 不弹出命令行窗口

-i 设定程序图标 ,其后面的ico文件就是程序图标

index.py 就是要打包的程序

-c 生成的exe文件打开方式为控制台打开。

2. 编译exe文件

pyinstaller -F --onefile index.spec

二、问题

1.file already exists but should not:\torch\_C.cp37-win_amd64.pyd

首先找到.spec配置文件修改配置文件,在配置文件中加入以下代码:

for d in a.datas:if '_C.cp37-win_amd64.pyd' in d[0]:a.datas.remove(d)break

详细的.spec配置文件的内容如下:

# -*- mode: python ; coding: utf-8 -*-block_cipher = Nonea = Analysis(['index.py'],pathex=['C:\\Users\\hp\\PycharmProjects\\NSBRMTS'],binaries=[],datas=[],hiddenimports=[],hookspath=[],runtime_hooks=[],excludes=[],win_no_prefer_redirects=False,win_private_assemblies=False,cipher=block_cipher,noarchive=False)for d in a.datas:if '_C.cp37-win_amd64.pyd' in d[0]:a.datas.remove(d)breakpyz = PYZ(a.pure, a.zipped_data,cipher=block_cipher)exe = EXE(pyz,a.scripts,a.binaries,a.zipfiles,a.datas,[],name='index',debug=False,bootloader_ignore_signals=False,strip=False,upx=True,upx_exclude=[],runtime_tmpdir=None,console=True , icon='logo.ico')

再对index.spec进行编译

2.Nosuchfileordirectory:'C:\\Users\\hp\\AppData\\Local\\Temp\\_MEI150042\\pyecharts\\datasets\\map_filename.json'

重新安装pyecharts1.5.1版本

pip install pyecharts==1.5.1

在PyInstaller安装目录下

C:\Users\hp\Anaconda3\Lib\site-packages\PyInstaller\hooks 需要增加如下文件

hook-pyecharts.py 文件内容:

#-----------------------------------------------------------------------------# Copyright (c) -, PyInstaller Development Team.## Distributed under the terms of the GNU General Public License (version 2# or later) with exception for distributing the bootloader.## The full license is in the file COPYING.txt, distributed with this software.## SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)#----------------------------------------------------------------------------- # Hook for nanite: /pypi/nanite from PyInstaller.utils.hooks import collect_data_files datas = collect_data_files('pyecharts')

然后删除工程下面xxxxx.spec 文件,重新打包,即可。

3.importlib_metadata.PackageNotFoundError: No package metadata was found for prettytable

安装importlib_metadata包

未解决

参考链接:

/huangjiyong/p/12436236.html

/bob-jianfeng/p/12112772.html

/skj1995/article/details/81187954

/LoveOpenSourceBoy/p/14192260.html

/LoveOpenSourceBoy/p/14192260.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。