从.py文件编译.exe时,如何修复“ ImportError:DLL加载失败”?

时间:2019-04-16 14:19:33

标签: python python-3.x pyinstaller

我是编程新手。我有一个Python代码(名为“ adm_dicing.py”),其中包括一些模块(numpy,scipy,matplotlib等)以及一些我自己编写的模块。它进行一些计算并绘制一些数字(如果代码中的 name = main ,我没有写过)。当我通过输入以下命令在Windows(我有Windows 7)的Windows命令行上编译代码时:

"C:\ProgramData\Anaconda3\Scripts\pyinstaller.exe" adm_dicing.py

我只有一个.spec文件,其中包含:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['adm_dicing.py'],
             pathex=['E:\\XiaoZhang\\Projet_R4-8_endoscope\\python codes'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='adm_dicing',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='adm_dicing')

,在命令行中,我看到以下消息和错误:

483 INFO: PyInstaller: 3.4
483 INFO: Python: 3.7.3
483 INFO: Platform: Windows-7-6.1.7601-SP1
483 INFO: wrote E:\XiaoZhang\Projet_R4-8_endoscope\python codes\adm_dicing.spec
499 INFO: UPX is not available.
500 INFO: Extending PYTHONPATH with paths
['E:\\XiaoZhang\\Projet_R4-8_endoscope\\python codes',
 'E:\\XiaoZhang\\Projet_R4-8_endoscope\\python codes']
500 INFO: checking Analysis
500 INFO: Building Analysis because Analysis-00.toc is non existent
500 INFO: Initializing module dependency graph...
507 INFO: Initializing module graph hooks...
566 INFO: Analyzing base_library.zip ...
15208 INFO: running Analysis Analysis-00.toc
15253 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of
final executable
  required by C:\ProgramData\Anaconda3\python.exe
16945 INFO: Caching module hooks...
16959 INFO: Analyzing E:\XiaoZhang\Projet_R4-8_endoscope\python codes\adm_dicing
.py
22825 INFO: Processing pre-find module path hook   distutils
23711 INFO: Processing pre-safe import module hook   six.moves
33828 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves

36851 INFO: Processing pre-find module path hook   site
36866 INFO: site: retargeting to fake-dir 'C:\\ProgramData\\Anaconda3\\lib\\site
-packages\\pyinstaller-3.4-py3.7.egg\\PyInstaller\\fake-modules'
99586 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
162520 INFO: Processing pre-safe import module hook   win32com
302047 INFO: Loading module hooks...
302047 INFO: Loading module hook "hook-babel.py"...
314303 INFO: Loading module hook "hook-bokeh.py"...
314694 INFO: Loading module hook "hook-certifi.py"...
314694 INFO: Loading module hook "hook-cryptography.py"...
316382 INFO: Loading module hook "hook-cytoolz.itertoolz.py"...
316401 INFO: Loading module hook "hook-distutils.py"...
316408 INFO: Loading module hook "hook-docutils.py"...
324213 INFO: Loading module hook "hook-encodings.py"...
324774 INFO: Loading module hook "hook-h5py.py"...
324786 INFO: Loading module hook "hook-IPython.py"...
324929 INFO: Excluding import 'matplotlib'
324945 INFO:   Removing import of matplotlib.pyplot from module IPython.core.pyl
abtools
324945 INFO:   Removing import of matplotlib from module IPython.core.pylabtools

324945 INFO:   Removing import of matplotlib.figure from module IPython.core.pyl
abtools
324945 INFO:   Removing import of matplotlib._pylab_helpers from module IPython.
core.pylabtools
324945 INFO: Excluding import 'PyQt5'
324945 INFO:   Removing import of PyQt5 from module IPython.external.qt_loaders
324945 INFO:   Removing import of PyQt5.QtWidgets from module IPython.external.q
t_loaders
324945 INFO:   Removing import of PyQt5.QtGui from module IPython.external.qt_lo
aders
324945 INFO:   Removing import of PyQt5.QtSvg from module IPython.external.qt_lo
aders
324945 INFO:   Removing import of PyQt5.QtCore from module IPython.external.qt_l
oaders
324945 INFO: Excluding import 'PyQt4'
324960 INFO:   Removing import of PyQt4 from module IPython.external.qt_loaders
324976 INFO: Excluding import 'PySide'
324976 INFO:   Removing import of PySide from module IPython.external.qt_loaders

324976 INFO: Excluding import 'tkinter'
324991 INFO:   Removing import of tkinter from module IPython.lib.clipboard
324991 INFO: Excluding import 'gtk'
324991 INFO: Loading module hook "hook-jedi.py"...
325023 INFO: Loading module hook "hook-jinja2.py"...
325038 INFO: Loading module hook "hook-jsonschema.py"...
325054 INFO: Loading module hook "hook-lib2to3.py"...
325085 INFO: Loading module hook "hook-lxml.etree.py"...
325085 INFO: Loading module hook "hook-matplotlib.backends.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line
 141, in <module>
    from . import cbook, rcsetup
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py"
, line 33, in <module>
    import numpy as np
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140,
 in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py",
line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
325986 INFO: Loading module hook "hook-matplotlib.py"...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\__init__.py", line
 141, in <module>
    from . import cbook, rcsetup
  File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py"
, line 33, in <module>
    import numpy as np
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140,
 in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py",
line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
327061 INFO: Loading module hook "hook-numpy.core.py"...
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140,
 in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py",
line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\pkgutil.py", line 493, in find_loader
    spec = importlib.util.find_spec(fullname)
  File "C:\ProgramData\Anaconda3\lib\importlib\util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py", line 140,
 in <module>
    from . import _distributor_init
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\_distributor_init.py",
line 34, in <module>
    from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\utils\hooks\__init__.py", line 320, in get_module_file_attribute
    loader = pkgutil.find_loader(package)
  File "C:\ProgramData\Anaconda3\lib\pkgutil.py", line 499, in find_loader
    raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for 'numpy.core' (<class 'ImportError'>:
 DLL load failed: The specified module could not be found.)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\Scripts\pyinstaller-script.py", line 11, in <mo
dule>
    load_entry_point('PyInstaller==3.4', 'console_scripts', 'pyinstaller')()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'
))
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 17, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\build_main.py", line 500, in assemble
    module_hook.post_graph()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\compat.py", line 736, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrappe
r
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\hooks\hook-numpy.core.py", line 27, in <module>
    pkg_base, pkg_dir = get_package_paths('numpy.core')
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\utils\hooks\__init__.py", line 537, in get_package_paths
    file_attr = get_module_file_attribute(package)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pyinstaller-3.4-py3.7.egg\PyI
nstaller\utils\hooks\__init__.py", line 339, in get_module_file_attribute
    raise ImportError
ImportError

如何解决此问题?

请注意,我已经安装了pywin,这是最后一个Windows Visual Studio(但尚未安装任何扩展名)

编辑:我尝试使用不包含任何导入模块的代码,它工作正常。只要我包含“将numpy导入为np”之类的东西,事情就会出错...

0 个答案:

没有答案