pyinstaller打包提示“文件所在的卷已被外部更改,因此打开的文件不再有效。”

环境

  • anaconda : 24.1.2
  • python : 3.7.13
  • pyinstaller : 5.13.0

问题描述

之前使用pyintaller执行spec文件打包都是能成功,今天打包报了“文件所在的卷已被外部更改,因此打开的文件不再有效。”的错误

Traceback (most recent call last):
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\isolated\_child.py", line 63, in run_next_command
    output = function(*args, **kwargs)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\building\build_main.py", line 187, in find_binary_dependencies
    return bindepend.Dependencies(binaries, redirects=binding_redirects, xtrapath=extra_libdirs)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\depend\bindepend.py", line 275, in Dependencies
    for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\depend\bindepend.py", line 449, in getAssemblyFiles
    for assembly in getAssemblies(pth):
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\depend\bindepend.py", line 403, in getAssemblies
    res = winmanifest.GetManifestResources(pth)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 979, in GetManifestResources
    return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\utils\win32\winresource.py", line 155, in GetResources
    hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\win32ctypes\pywin32\win32api.py", line 40, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (1006, 'LoadLibraryEx', '文件所在的卷已被外部更改,因此打开的文件不再有效。')

排查思路

  • 搜索网上说是杀毒软件隔离问题,停用掉杀毒软件,无效
  • 继续搜索说是pyinstaller版本多个的问题,由于我是有两套pyisntaller,一套是本机环境,一套是anaconda的环境,为了避免这个问题,我把本机的pyinstaller uninstall掉,还是无法解决我的问题
  • 还有说是缓存的问题,我尝试着清除了pyinstaller的缓存还重装了pyinstaller,还是无法解决!
  • 最后只能去github的pyinstaller查找issue,发现了有一个和我一样的报错,详见
    github issue
    看了一下文中的描述和我的没有关系,但是文中提到了一种排查方法就是打开debug日志
    打开debug日志
    尝试着打开debug日志,发现了pyinstaller是在分析./logs/app.log文件的时候报错了
pyinstaller ***.spec --log-level DEBUG

定位报错
app.log是个日志文件,突然间想到当时为了减轻打包的文件大小,故意将他清空了内容,容量为0KB,难不成是0KB读取不了!于是试着对app.log随便编辑写入一些内容,有了大小,结果重新打包真的成功了!

总结

综上所述,由于app.log是作为二进制文件打包进入的(见下图的spec文件),pyintaller估计在读取该文件的时候字节数量为0报错了,当重新给app.log写入内容就可以读取成功
spec内容

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当在使用pyinstaller打包时出现'pyinstaller' 不是内部或外部命令,也不是可运行的程序 或批处理文件的错误提示时,可以按照以下步骤解决: 1. 首先,确保已经正确安装了pyinstaller。使用命令pip install pyinstaller来安装pyinstaller,如果已经安装过了可以跳过这一步。 2. 如果已经安装过pyinstaller但仍然出现错误提示,可能是因为系统环境变量没有正确配置。需要将pyinstaller所在的路径添加到系统环境变量中。 3. 打开命令提示符(cmd),输入echo %PATH%命令来查看当前的系统环境变量。 4. 在输出结果中查找是否包含了pyinstaller所在的路径。如果没有找到,需要手动将其添加到环境变量中。 5. 打开“控制面板”->“系统和安全”->“系统”,点击左侧的“高级系统设置”。 6. 在弹出的窗口中,点击“环境变量”按钮。 7. 在“系统变量”下方的列表中,找到名为“Path”的变量,双击打开。 8. 在变量值的末尾添加pyinstaller所在的路径,确保路径之间使用分号进行分隔。 9. 点击“确定”保存修改。 10. 关闭命令提示符,并重新打开一个新的命令提示符窗口。 11. 输入pyinstaller命令来验证是否已经成功解决问题。如果没有再次出现错误提示,那么问题已经解决。 通过以上步骤,应该可以解决'pyinstaller' 不是内部或外部命令,也不是可运行的程序 或批处理文件的错误提示,使得pyinstaller能够正常打包你的py文件为exe文件。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [python3.7以上使用pyinstaller将py文件打包为exe ,解决安装后显示‘pyinstaller‘ 不是内部或外部命令,也...](https://blog.csdn.net/weixin_47761086/article/details/125627228)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [Python——执行打包提示pyinstaller‘ 不是内部或外部命令,也不是可运行的程序](https://blog.csdn.net/weixin_40587180/article/details/117485581)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值