PyInstaller打包Pywallet生成exe后创建钱包FileNotFoundError解决方案
问题复现
使用PyInstaller将Python编写的比特币钱包程序打包为exe可执行文件,运行打包后的程序并尝试创建新钱包时出现如下报错:
Traceback (most recent call last): File "btcwallet.py", line 111, in <module> File "btcwallet.py", line 80, in menu File "btcwallet.py", line 47, in save_wallet File "btcwallet.py", line 40, in generate_wallet File "pywallet\wallet.py", line 13, in generate_mnemonic File "pywallet\utils\ethereum.py", line 1321, in master_key_from_entropy File "mnemonic\mnemonic.py", line 47, in __init__ FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mistr\\AppData\\Local\\Temp\\_MEI35242\\mnemonic\\wordlist/english.txt' [2548] Failed to execute script 'btcwallet' due to unhandled exception!
原因说明
报错核心是mnemonic助记词库自带的english.txt词表资源文件没有被PyInstaller打包进最终的exe文件。程序运行时会在PyInstaller生成的临时解压目录下查找该文件,找不到就触发文件不存在异常。
解决方法
直接使用以下打包命令即可修复该问题:
pyinstaller --onefile --collect-all mnemonic --hidden-import mnemonic btcwallet.py
命令参数说明
--collect-all mnemonic:强制PyInstaller收集mnemonic库的所有关联文件,包括代码、资源、元数据等,确保词表文件被打包--hidden-import mnemonic:显式指定mnemonic为隐式导入依赖,避免PyInstaller扫描导入关系时漏识别该库--onefile:将程序和所有依赖打包为单个独立的exe可执行文件
内容的提问来源于stack exchange,提问作者Haniewas
相关产品推荐
相关产品推荐

