PyInstaller win32ctypes.pywin32.pywintypes.error:(2,'LoadLibraryExW','系统找不到指定的文件.') [英] PyInstaller win32ctypes.pywin32.pywintypes.error: (2, 'LoadLibraryExW', 'The system cannot find the file specified.')

查看:1675
本文介绍了PyInstaller win32ctypes.pywin32.pywintypes.error:(2,'LoadLibraryExW','系统找不到指定的文件.')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PyInstaller(开发版本为4.0.dev0 + 8196c57ab)时,产生了OSError: [WinError 2] 'The system cannot find the file specified.'

While using PyInstaller (dev version 4.0.dev0+8196c57ab), produced an OSError: [WinError 2] 'The system cannot find the file specified.'

  • Python版本:3.7
  • GUI:PySide2 5.13.0
  • 其他软件包:lxml,BeautifulSoup,Matplotlib(具有numpy之类的依赖项),Pandas,pypiwin32,reportlab,Theano
  • Anaconda 3,Windows
  • 使用PyInstaller --onedir编译

我尝试过的事情:

  • 尝试按照以下建议将PyInstaller降级到2.1: https://github.com/pyinstaller/pyinstaller/issues/3916 ,但由于不支持Python 3而无法正常运行
  • 最初是PyInstaller 3.5上的版本,根据PyInstaller github上某些问题的建议升级到开发版本.
  • 尝试包括--exclude-module=.git
  • Tried downgrading PyInstaller to 2.1 as suggested here: https://github.com/pyinstaller/pyinstaller/issues/3916 but doesn't work as Python 3 is not supported
  • Was originally on PyInstaller 3.5, upgraded to dev version as suggested under some of the issues on PyInstaller github
  • Tried including --exclude-module=.git
import PyInstaller.__main__

if __name__ == '__main__':
    PyInstaller.__main__.run([
        '--name=%s' % 'Dummy App',
        '--onedir',
        '--nowindowed',
        r'--workpath=C:\Users\User1\Desktop\build7',
        r'--distpath=C:\Users\User1\Desktop\dist7',
        '--hidden-import=theano.tensor.shared_randomstreams',
        '--hidden-import=pandas._libs.tslibs.timedeltas',
        '--clean',
        '--add-data={0};.'.format('redacted.xml'),
        '--add-data={0};{0}'.format('redacted_folder'),
        '--add-data={0};.'.format('redacted.pdf'),
        '--exclude-module={0}'.format('.git'),
        '--log-level=WARN',
        'MainWindow.py'
    ])

完整的堆栈跟踪:

79702 DEBUG: Analyzing .git\objects\78\e83411cea88cd038acb12c005a984fc0d6d423
Traceback (most recent call last):
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 35, in pywin32error
    yield
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\core\ctypes\_util.py", line 42, in check_null
    raise make_error(function, function_name)
OSError: [WinError 2] The system cannot find the file specified.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/User1/Dropbox/GitHub_Repos/DiabetesReportGenerator_v2/pyinstaller_freeze.py", line 37, in <module>
    'MainWindow.py'
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\__main__.py", line 112, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 732, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 679, in build
    exec(code, spec_namespace)
  File "C:\Users\User1\Dropbox\GitHub_Repos\DiabetesReportGenerator_v2\Risk Calculator.spec", line 17, in <module>
    noarchive=False)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
    self.__postinit__()
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\building\build_main.py", line 468, in assemble
    redirects=self.binding_redirects))
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 226, in Dependencies
    for ftocnm, fn in getAssemblyFiles(pth, manifest, redirects):
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 402, in getAssemblyFiles
    for assembly in getAssemblies(pth):
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\depend\bindepend.py", line 353, in getAssemblies
    res = GetManifestResources(pth)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\utils\win32\winmanifest.py", line 1005, in GetManifestResources
    return winresource.GetResources(filename, [RT_MANIFEST], names, languages)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\PyInstaller\utils\win32\winresource.py", line 168, in GetResources
    hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\win32api.py", line 43, in LoadLibraryEx
    return _dll._LoadLibraryEx(fileName, 0, flags)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\User1\Anaconda3\envs\ids_gui\lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (2, 'LoadLibraryExW', 'The system cannot find the file specified.')

P.S.编译和exe可以与早先从Anaconda环境创建的virtualenv环境(不需要--exclude-module=.git)一起正常运行,但是打包太肿,因为virtualenv环境仍然被认为是conda环境的一部分.所以我使用了一个新的conda环境,并且出现了这个错误

P.S. Compilation and the exe functioned perfectly with virtualenv environment created from Anaconda environment earlier (without need for --exclude-module=.git), but was too bloated with packages because the virtualenv environment is still considered to be part of the conda environment. So I used a new conda environment, and this error appeared

我已经通过在这个新的conda环境中创建另一个virtualenv环境来使其工作,但这是一种非常round回的方式.有什么解决方法吗?

I've gotten it to work by creating another virtualenv environment in this new conda environment, but that is a very roundabout way. Is there any workaround?

推荐答案

对我来说,PyInstaller似乎不必要地搜索.git文件夹和redacted_folder

For me, PyInstaller seems to search through .git folder and redacted_folder unnecessarily

我通过以下方法解决了这个问题:

I solved this problem by:

  1. 在冻结之前将文件夹移出目录

此外,如果要运行冻结的应用程序需要该文件夹(例如,作为数据文件夹),我也可以:

Additionally, if the folder is required for the frozen app to run (e.g. as a data folder), I would also either:

  • 注释/删除--add-data的相应部分,然后手动复制文件夹,或者

  • Comment / remove the corresponding part for --add-data and manually copy the folder over, or

更改--add-data的路径,例如如果将redacted_folder移至桌面,则可以更改为'--add-data=C:/Users/User1/Desktop/redacted_folder'

Change the path for --add-data e.g. if you moved redacted_folder to your Desktop, you can change to '--add-data=C:/Users/User1/Desktop/redacted_folder'

您仍然需要在原始目录中返回.gitredacted_folder才能使用Git并在不冻结的情况下运行代码

You'll still need .git and redacted_folder back in the original directory to use Git and run your code without freezing

例如,我在.gitredacted_folder上遇到麻烦.冻结的可执行文件需要redacted_folder才能运行部分代码.

For example, I had trouble with .git and redacted_folder. The frozen executable needed redacted_folder to run parts of the code.

我所做的是:

  1. .gitredacted_folder移动到单独的目录

然后,我注释掉为redacted_folder添加数据的行:

Then, I commented out the line to add data for redacted_folder:

import PyInstaller.__main__

if __name__ == '__main__':
    PyInstaller.__main__.run([
        '--name=%s' % 'Dummy App',
        '--onedir',
        '--nowindowed',
        r'--workpath=C:\Users\User1\Desktop\build7',
        r'--distpath=C:\Users\User1\Desktop\dist7',
        '--hidden-import=theano.tensor.shared_randomstreams',
        '--hidden-import=pandas._libs.tslibs.timedeltas',
        '--clean',
        '--add-data={0};.'.format('redacted.xml'),
        # Remove `redacted_folder` and comment out the following line
        # '--add-data={0};{0}'.format('redacted_folder'),
        '--add-data={0};.'.format('redacted.pdf'),
        '--exclude-module={0}'.format('.git'),
        '--log-level=WARN',
        'MainWindow.py'
    ])

  1. 冻结后,我将redacted_folder复制到相对于distpath中冻结的可执行文件的适当位置.
  1. After freezing, I copied redacted_folder over to the appropriate location relative to the frozen executable in distpath

这篇关于PyInstaller win32ctypes.pywin32.pywintypes.error:(2,'LoadLibraryExW','系统找不到指定的文件.')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆