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

Miniconda+Python3.8环境下Tensorflow缺失msvcp140_1.dll问题及解决方法

Fixing "msvcp140_1.dll Not Found" Error with TensorFlow in Miniconda (Python 3.8+)

What I Ran Into

I set up a TensorFlow environment using Miniconda with this command:

conda create -n tf tensorflow

But when I tried running my code in VS Code using the tf environment's interpreter, I kept getting an error saying msvcp140_1.dll couldn't be found. TensorFlow's error message told me to install the Microsoft C++ Redistributable for Visual Studio 2015, 2017 and 2019, so I reinstalled the x64 version three times. I even confirmed the DLL existed in multiple locations:

  • C:\Users\myusername\miniconda3\envs\tf\msvcp140_1.dll
  • C:\Users\myusername\miniconda3\envs\tf\Library\bin\msvcp140_1.dll
  • C:\Windows\System32\msvcp140_1.dll
  • C:\Users\myusername\miniconda3\Library\bin\msvcp140_1.dll
  • C:\Users\myusername\miniconda3\msvcp140_1.dll

Most online fixes just said to install that redistributable package, but that didn't work for me at all. I spent hours digging through forums until I found a solution from Eryk Sun's comments that finally fixed the problem.

The Fix That Worked

I modified TensorFlow's self_check.py file to add winmode=0 to the ctypes.WinDLL call. Here's how:

  1. Navigate to the self_check.py file in your Conda environment's TensorFlow folder. For me, that was:
    C:\Users\myusername\miniconda3\envs\tf\Lib\site-packages\tensorflow\python\platform\self_check.py
    
  2. Find the line where ctypes.WinDLL is being used to load a DLL related to the redistributable check.
  3. Update the line to include winmode=0:
    Before:
    ctypes.WinDLL(dll_name)
    
    After:
    ctypes.WinDLL(dll_name, winmode=0)
    
  4. Save the file, then re-run your TensorFlow code. The error should be gone.

Why This Works (Thanks to Eryk Sun's Technical Explanation)

Starting with Python 3.8, the DLL search behavior changed. The old way where ctypes.WinDLL(dll_name) used the system PATH to find DLLs is no longer the default. Now Python only looks in:

  • The application directory (like your Conda env's sys.prefix folder)
  • The System32 directory
  • Paths you've explicitly added using os.add_dll_directory()

TensorFlow's code was still relying on the old PATH-based search. Adding winmode=0 forces the WinDLL call to use the legacy search behavior, which picks up the DLL even if it's in a path that isn't in the process's official DLL search list.

I can't say if this is the perfect long-term solution, but it worked immediately for me when nothing else did.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.29 20:28:11