ImportError: DLL load failed while importing _path

Hi all,

Been trying to fix this for hours without luck, could use some assistance.

Im running Python in VS Code and I use Python Packages both in Streamlit and Power BI - however all of a sudden today none of the external apps can run / find the packages. I tried to reinstall Python multiple times.

I get this message “ImportError: DLL load failed while importing _path”

File “C:\Users\cesc\OneDrive - Company\Report.py”, line 5, in
import matplotlib.pyplot as plt

I tried uninstalling (pip) and installing the package again, I just get this when I run pip install in terminal (a part of the response):

"
PS C:\Users\cesc> pip install matplotlib
Requirement already satisfied: matplotlib in c:\users\cesc\lib\site-packages (3.9.2)
Requirement already satisfied: contourpy>=1.0.1 in c:\users\cesc\appdata\roaming\python\python312\site-packages (from matplotlib) (1.2.0)
"

Thanks in advance.

dlltracer · PyPI won’t solve the problem directly, but it may provide more info on whether any DLL loads are working (the last one printed is the last one that worked).

When i pip install dlltracer in my PowerShell, I get this:

PS C:\Users\cesc> import dlltracer
import : The term ‘import’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1

  • import dlltracer
  •   + CategoryInfo          : ObjectNotFound: (import:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException

dlltracer is a Python module - it needs to be loaded and enabled in a script before you try the same import that is failing in your main script.

This is failing to import a compiled c-extension from Matplotlib (for working on graphical “paths” not filesystem “paths”). This error suggests that something has gone wrong with the installation process.

I would suggest:

  • pip install --force matplotlib which will force renistallation (in the log above pip is telling you it thinks Matplotlib is installed from its static metadata so it does nothing, but that is no guarantee it is actually correctly installed)
  • check that you are installing into the same Python environment that your tools are using
1 Like

Thanks. How can I check if I am installing into thhe correct environment / path?