You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Anaconda环境下.py转.exe时numpy DLL加载失败错误求助

我是编程新手,尝试将.py文件转换为可执行.exe文件时遇到以下错误。我的numpy版本为1.19.1(已卸载重装),Anaconda版本为1.9.12,PYTHONPATH配置正常。使用auto-py-to-exe v2.7.6调用PyInstaller 3.6打包C:/Users/User/Documents/Python/Scripts/Italiano/conjugacion_verbos_presente/auxiliar.py时,出现如下报错:

Running auto-py-to-exe v2.7.6
Building directory: C:\Users\User\AppData\Local\Temp\tmp30rpmpfm
Provided command: pyinstaller --noconfirm --onedir --windowed "C:/Users/User/Documents/Python/Scripts/Italiano/conjugacion_verbos_presente/auxiliar.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onedir --windowed C:/Users/User/Documents/Python/Scripts/Italiano/conjugacion_verbos_presente/auxiliar.py --distpath C:\Users\User\AppData\Local\Temp\tmp30rpmpfm\application --workpath C:\Users\User\AppData\Local\Temp\tmp30rpmpfm\build --specpath C:\Users\User\AppData\Local\Temp\tmp30rpmpfm
520727 INFO: PyInstaller: 3.6
520732 INFO: Python: 3.7.6 (conda)
520736 INFO: Platform: Windows-10-10.0.18362-SP0
520746 INFO: wrote C:\Users\User\AppData\Local\Temp\tmp30rpmpfm\auxiliar.spec
520753 INFO: UPX is not available.
520761 INFO: Extending PYTHONPATH with paths ['C:\\Users\\User\\Documents\\Python\\Scripts\\Italiano', 'C:\\Users\\User\\AppData\\Local\\Temp\\tmp30rpmpfm']
520765 INFO: checking Analysis
520769 INFO: Building Analysis because Analysis-01.toc is non existent
520774 INFO: Reusing cached module dependency graph...
520878 INFO: Caching module graph hooks...
521005 INFO: running Analysis Analysis-01.toc
521011 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by C:\Anaconda3\python.exe
521620 INFO: Analyzing C:\Users\User\Documents\Python\Scripts\Italiano\conjugacion_verbos_presente\auxiliar.py
527431 INFO: Processing pre-find module path hook distutils
527438 INFO: distutils: retargeting to non-venv dir 'C:\\Anaconda3\\lib'
533043 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
534572 INFO: Processing pre-find module path hook site
534577 INFO: site: retargeting to fake-dir 'C:\\Anaconda3\\lib\\site-packages\\PyInstaller\\fake-modules'
547576 INFO: Processing module hooks...
547582 INFO: Loading module hook "hook-distutils.py"...
547591 INFO: Loading module hook "hook-encodings.py"...
547763 INFO: Loading module hook "hook-importlib_metadata.py"...
547772 INFO: Loading module hook "hook-lib2to3.py"...
547785 INFO: Loading module hook "hook-numpy.core.py"...
An error occurred while packaging
Traceback (most recent call last):
  File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 24, in <module>
    from . import multiarray
  File "C:\Anaconda3\lib\site-packages\numpy\core\multiarray.py", line 14, in <module>
    from . import overrides
  File "C:\Anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
    from numpy.core._multiarray_umath import (
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:\Anaconda3\lib\pkgutil.py", line 493, in find_loader
    spec = importlib.util.find_spec(fullname)
  File "C:\Anaconda3\lib\importlib\util.py", line 94, in find_spec
    parent = __import__(parent_name, fromlist=['__path__'])
  File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 142, in <module>
    from . import core
  File "C:\Anaconda3\lib\site-packages\numpy\core\__init__.py", line 54, in <module>
    raise ImportError(msg)
ImportError: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.

- Try uninstalling and reinstalling numpy.
- If you have already done that, then:

1. Check that you expected to use Python3.7 from "C:\Anaconda3\python.exe",
   and that you have no directories in your PATH or PYTHONPATH that can
   interfere with the Python and numpy version "1.18.1" you're trying to use.

2. If (1) looks fine, you can open a new issue at
   https://github.com/numpy/numpy/issues. Please include details on:

- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: 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:\Anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 320, in get_module_file_attribute
    loader = pkgutil.find_loader(package)
  File "C:\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'>: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions failed.

- Try uninstalling and reinstalling numpy.
- If you have already done that, then:

1. Check that you expected to use Python3.7 from "C:\Anaconda3\python.exe",
   and that you have no directories in your PATH or PYTHONPATH that can
   interfere with the Python and numpy version "1.18.1" you're trying to use.

2. If (1) looks fine, you can open a new issue at
   https://github.com/numpy/numpy/issues. Please include details on:

- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.

Original error was: 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:\Users\User\Desktop\auto-py-to-exe-master\auto_py_to_exe\packaging.py", line 131, in package
    run_pyinstaller()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 114, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 734, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 681, in build
    exec(code, spec_namespace)
  File "C:\Users\User\AppData\Local\Temp\tmp30rpmpfm\auxiliar.spec", line 17, in <module>
    noarchive=False)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 244, in __init__
    self.__postinit__()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
    self.assemble()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 422, in assemble
    self.graph.process_post_graph_hooks()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 311, in process_post_graph_hooks
    module_hook.post_graph()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\depend\imphook.py", line 417, in post_graph
    self._load_hook_module()
  File "C:\Anaconda3\lib\site-packages\PyInstaller\depend\imphook.py", line 384, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\compat.py", line 797, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  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:\Anaconda3\lib\site-packages\PyInstaller\hooks\hook-numpy.core.py", line 29, in <module>
    pkg_base, pkg_dir = get_package_paths('numpy.core')
  File "C:\Anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 537, in get_package_paths
    file_attr = get_module_file_attribute(package)
  File "C:\Anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 339, in get_module_file_attribute
    raise ImportError
ImportError
Project output will not be moved to output folder
Complete.

解决方案

这个问题的核心是PyInstaller 3.6对Anaconda环境下numpy 1.19.x的C扩展依赖处理不完善,加上环境中存在numpy版本冲突(报错里显示的1.18.1和你安装的1.19.1不一致,说明有旧版本残留),导致打包时找不到必要的DLL文件。下面是几个逐步排查的解决办法:

1. 优先升级PyInstaller到兼容版本

PyInstaller 3.6是2019年的旧版本,对后续numpy版本的支持有限。先升级到最新稳定版:

pip install --upgrade pyinstaller

升级后重启auto-py-to-exe再尝试打包,新版本优化了numpy依赖的识别逻辑,大概率能解决DLL缺失问题。

2. 清理numpy版本冲突

报错里的版本不一致说明环境中有残留的旧版numpy,先彻底清理再重新安装:

# 卸载所有numpy版本
conda uninstall numpy --all
pip uninstall numpy --yes

# 用conda重新安装指定版本(conda安装会自动处理DLL依赖,适配Anaconda环境)
conda install numpy==1.19.1

3. 使用纯净虚拟环境打包

Anaconda环境自带依赖多,容易出现冲突。建议创建专门的打包虚拟环境:

# 创建并激活虚拟环境
conda create -n pack_env python=3.7.6
conda activate pack_env

# 安装打包所需依赖
pip install numpy==1.19.1 auto-py-to-exe

# 在这个环境里运行auto-py-to-exe,选择你的脚本打包

虚拟环境能隔离无关依赖,彻底避免版本冲突。

4. 手动添加numpy的DLL目录到打包参数

如果以上方法都不行,可以手动指定numpy的DLL路径让PyInstaller包含:

  1. 找到numpy的DLL目录:Anaconda环境下是C:\Anaconda3\Lib\site-packages\numpy\.libs,虚拟环境下是C:\Users\User\.conda\envs\pack_env\Lib\site-packages\numpy\.libs
  2. 在auto-py-to-exe的Advanced选项卡中,找到Additional Files,点击Add Files/Folder选择这个.libs目录
  3. 设置Destination为.numpy/.libs(保持相对路径,确保打包后程序能找到DLL)
  4. 重新打包

额外提示

  • 检查PATH环境变量,确保Anaconda环境的路径排在其他Python版本前面,避免依赖加载混乱
  • 如果用--windowed参数打包失败,先尝试--console参数测试,控制台会输出更详细的错误信息,方便排查

内容的提问来源于stack exchange,提问作者Ale Hostar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 19:42:37