LoginSignup
4
2

More than 1 year has passed since last update.

[Python] matplotlibを使おうとしたらImportError: DLL load failed while importing _cextが出てハマった

Last updated at Posted at 2023-04-13

概要

matplotlibをimportしたファイルを実行したところ,ImportError: DLL load failed while importing _cextが出てしまいました.
msvc-runtimeをインストールすることで解決しました.

環境

OS : Windows10
エディタ : VS Code
Python : 3.11.3
matplotlib : 3.7.1

起こったこと

VS Codeで,matplotlibを用いたプログラムを作成するため,同ライブラリをインストールしました.

pip install matplotlib
~中略~
Successfully installed matplotlib-3.7.1

次のようにimportし,プログラムを作成・実行したところ,

.py
import matplotlib.pyplot as plt

下記のエラーが発生して止まってしまいました.

~上略~
File "C:\Users\Username\AppData\Local\Programs\Python\Python311\Lib\site-packages\kiwisolver\__init__.py", line 8, in <module>
    from ._cext import (
ImportError: DLL load failed while importing _cext: 指定されたモジュールが見つかりません。

解決策

結論,msvc-runtimeのインストールで解決しました.

pip install msvc-runtime
~中略~
Successfully installed msvc-runtime-14.34.31931

実のところ自分で読み解いたわけではなく,stack overflowにそのままの答えがありました…
https://stackoverflow.com/questions/75824703/matplotlib-importerror-dll-load-failed-while-importing-cext

検索しても意外と引っかからなかったのと,環境構築自体が久しぶりなのもありだいぶハマったので.困っている人の検索に引っかかればいいなと思い投稿することにしました.
たまたまハマった少数派なのかもしれないし,そもそも自分の検索能力が低かっただけという話ではあります…

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2