Trying to understand source of DLL error when installing for development

I get the following error after attempting to install matplotlib for development following the directions here:

testing.py
  File "D:\Atom\VENVs\matplotlib\lib\matplotlib\__init__.py", line 161, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "D:\Atom\VENVs\matplotlib\lib\matplotlib\cbook.py", line 32, in <module>
    from matplotlib import _api, _c_internal_utils
ImportError: DLL load failed while importing _c_internal_utils: The specified module could not be found.

The output of the install command is as follows (completes without obvious errors):

python -m pip install --verbose --no-build-isolation --editable .[dev]
Using pip 23.3.2 from D:\Atom\VENVs\mplt_env\Lib\site-packages\pip (python 3.11)
Obtaining file:///D:/Atom/venvs/matplotlib
  Running command Checking if build backend supports build_editable
  Checking if build backend supports build_editable ... done
  Running command Preparing editable metadata (pyproject.toml)
  + meson setup --reconfigure D:\Atom\venvs\matplotlib D:\Atom\venvs\matplotlib\build\cp311 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=D:\Atom\venvs\matplotlib\build\cp311\meson-python-native-file.ini
  Cleaning... 0 files.
  The Meson build system
  Version: 1.3.0
  Source dir: D:\Atom\VENVs\matplotlib
  Build dir: D:\Atom\VENVs\matplotlib\build\cp311
  Build type: native build
  Project name: matplotlib
  Project version: 3.9.0.dev0
  C compiler for the host machine: cc (gcc 13.1.0 "cc (Rev6, Built by MSYS2 project) 13.1.0")
  C linker for the host machine: cc ld.bfd 2.40
  C++ compiler for the host machine: c++ (gcc 13.1.0 "c++ (Rev6, Built by MSYS2 project) 13.1.0")
  C++ linker for the host machine: c++ ld.bfd 2.40
  Host machine cpu family: x86_64
  Host machine cpu: x86_64
  Program python found: YES (D:\Atom\VENVs\mplt_env\Scripts\python.exe)
  Dependency pybind11 found: YES 2.11.1 (cached)

  Executing subproject freetype-2.6.1

  freetype-2.6.1| Project name: freetype2
  freetype-2.6.1| Project version: 2.6.1
  freetype-2.6.1| C compiler for the host machine: cc (gcc 13.1.0 "cc (Rev6, Built by MSYS2 project) 13.1.0")
  freetype-2.6.1| C linker for the host machine: cc ld.bfd 2.40
  freetype-2.6.1| Configuring ftconfig.h using configuration
  freetype-2.6.1| Configuring ftoption.h using configuration
  freetype-2.6.1| Build targets in project: 3
  freetype-2.6.1| Subproject freetype-2.6.1 finished.


  Executing subproject qhull

  qhull| Project name: qhull
  qhull| Project version: 8.0.2
  qhull| C compiler for the host machine: cc (gcc 13.1.0 "cc (Rev6, Built by MSYS2 project) 13.1.0")
  qhull| C linker for the host machine: cc ld.bfd 2.40
  qhull| Build targets in project: 4
  qhull| Subproject qhull finished.

  Library dl found: NO
  Library comctl32 found: YES
  Library ole32 found: YES
  Library psapi found: YES
  Library shell32 found: YES
  Library user32 found: YES
  Configuring _version.py using configuration
  Program D:/Atom/VENVs/matplotlib/tools/generate_matplotlibrc.py found: YES (D:\Atom\VENVs\mplt_env\Scripts\python.exe D:/Atom/VENVs/matplotlib/tools/generate_matplotlibrc.py)
  Build targets in project: 14

  matplotlib 3.9.0.dev0

    Subprojects
      freetype-2.6.1: YES
      qhull         : YES

    User defined options
      Native files  : D:\Atom\venvs\matplotlib\build\cp311\meson-python-native-file.ini
      buildtype     : release
      b_ndebug      : if-release
      b_vscrt       : md

  Found ninja.EXE-1.11.1.git.kitware.jobserver-1 at D:\Atom\VENVs\mplt_env\Scripts\ninja.EXE
  + meson compile
  ninja: no work to do.
  INFO: autodetecting backend as ninja
  INFO: calculating backend command to run: D:\Atom\VENVs\mplt_env\Scripts\ninja.EXE
  Preparing editable metadata (pyproject.toml) ... done
  ...

Is this line relevant? Library dl found: NO
I’ve ensured the build dependencies are installed as well as MSVC.

Using:

  • Windows 10
  • Python 3.11

It appears that you are building with gcc, and not MSVC as you’ve expected.

If you want to force using MSVC, then you’ll want to pass the --vsenv option to Meson:

Thanks for the response, that makes sense. Unfortunately it’s now giving me a new error when I try forcing MSVC:

…..\meson.build:1:0: ERROR: Tried modify read only option ‘vsenv’

This happens regardless of what method I try to use to change the option (command-line or
pyproject.toml). I’m not sure what’s best to try next. Do you have any suggestions? Maybe just throw it at a Linux VM instead?

It sounds like you have an existing half-complete editable install, so make sure to clean your git checkout before using the new options.