环境
- 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_commandoutput = function(*args, **kwargs)File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\building\build_main.py", line 187, in find_binary_dependenciesreturn 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 Dependenciesfor 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 getAssemblyFilesfor assembly in getAssemblies(pth):File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\depend\bindepend.py", line 403, in getAssembliesres = winmanifest.GetManifestResources(pth)File "C:\Users\Lenovo\.conda\envs\python37_32\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 979, in GetManifestResourcesreturn 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 GetResourceshsrc = 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 LoadLibraryExreturn _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 pywin32errorraise 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日志,发现了pyinstaller是在分析./logs/app.log文件的时候报错了
pyinstaller ***.spec --log-level DEBUG
app.log是个日志文件,突然间想到当时为了减轻打包的文件大小,故意将他清空了内容,容量为0KB,难不成是0KB读取不了!于是试着对app.log随便编辑写入一些内容,有了大小,结果重新打包真的成功了!
总结
综上所述,由于app.log是作为二进制文件打包进入的(见下图的spec文件),pyintaller估计在读取该文件的时候字节数量为0报错了,当重新给app.log写入内容就可以读取成功