spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Anaconda's Spyder gives DLL load failure when connected to Msys2 Python interpreter

Open MustyHickory106 opened this issue 4 years ago • 2 comments

Motivation: The package of interest only works with GCC compiled Python, and I would like to use an IDE (Spyder) to interpret the GCC compiled Python which is not the default MSC version of Python included with Anaconda 3 on windows.

Issue: DLL load failed while importing [package name]: The specified procedure could not be found.

System information: Windows 10 Home Build 19043.1526 with WSL Enabled. Bash: MSYS2 MinGW x64 Spyder 5.1.5 gcc version 11.2.0 targeting x86_64-w64-ming32 Python 3.9.10 (main, Jan 25 2022, 17:58:23) [GCC 11.2.0 64 bit (AMD64)]

Reproducible Example:

-Download Anaconda 3 which includes Spyder and default MSC compiled Python

-Use Msys2 64 bit with Mingw64 to obtain GCC compiled python. To do so, you would need to use pacman to obtain mingw-w64-x86_64-toolchain and python for mingw64.

-Install common python packages such as numpy, scipy, and matplotlib using pacman. You will also need spyder dependencies such as spyder-kernels and IPython -If the dependencies are not satisfied, spyder will fail to start the kernel.

-At this stage, running python in mingw64 (by typing “python” in bash) should have no problems. -Importing packages should also have no problems. e.g, import matplotlib.pyplot

-Try using Anaconda 3 Spyder to interpret the GCC python by going to: Tool > Preferences > Python interpreter > Select Use the following python interpreter > Set the location to “path to msys2\mingw64\bin\python.exe

-Depending on the matplotlib graphical settings, you may or may not already receive an error in the console regarding a DLL load failure. -If not, then importing matplotlib.pyplot or importing scipy.optimize, should give you the error. -However, starting GCC python in mingw64 will have no problem importing these packages.

Errors upon starting console:

Python 3.9.10 (main, Jan 25 2022, 17:58:23)  [GCC 11.2.0 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython  -- An enhanced Interactive Python.

Output from spyder call 'show_mpl_backend_errors':

=========================================================================
NOTE: The following error appeared when setting your Matplotlib backend!!
=========================================================================

Traceback (most recent call last):
  File "C:\msys64\mingw64\lib\python3.9\site-packages\spyder_kernels\console\kernel.py", line 739, in _set_mpl_backend
    get_ipython().run_line_magic(magic, backend)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\IPython\core\interactiveshell.py", line 2364, in run_line_magic
    result = fn(*args, **kwargs)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\IPython\core\magic.py", line 187, in <lambda>
    call = lambda f, *a, **k: f(*a, **k)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\IPython\core\magics\pylab.py", line 99, in matplotlib
    gui, backend = self.shell.enable_matplotlib(args.gui.lower() if isinstance(args.gui, str) else args.gui)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\ipykernel\zmqshell.py", line 601, in enable_matplotlib
    gui, backend = super(ZMQInteractiveShell, self).enable_matplotlib(gui)
  File "C:\msys64\mingw64\lib\python3.9\site-packages\IPython\core\interactiveshell.py", line 3533, in enable_matplotlib
    from matplotlib_inline.backend_inline import configure_inline_support
  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib_inline\backend_inline.py", line 7, in <module>
    from matplotlib.backends.backend_agg import (  # noqa
  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\backends\backend_agg.py", line 35, in <module>
    from PIL import Image
  File "C:\msys64\mingw64\lib\python3.9\site-packages\PIL\Image.py", line 89, in <module>
    from . import _imaging as core
ImportError: DLL load failed while importing _imaging: The specified procedure could not be found.

Importing matplotlib

In [1]: import matplotlib.pyplot
Traceback (most recent call last):

  File "<ipython-input-1-864e826dab68>", line 1, in <module>
    import matplotlib.pyplot

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\pyplot.py", line 36, in <module>
    import matplotlib.colorbar

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\colorbar.py", line 44, in <module>
    import matplotlib.contour as contour

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\contour.py", line 17, in <module>
    import matplotlib.text as text

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\text.py", line 16, in <module>
    from .textpath import TextPath  # Unused, but imported by others.

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\textpath.py", line 11, in <module>
    from matplotlib.mathtext import MathTextParser

  File "C:\msys64\mingw64\lib\python3.9\site-packages\matplotlib\mathtext.py", line 27, in <module>
    from PIL import Image

  File "C:\msys64\mingw64\lib\python3.9\site-packages\PIL\Image.py", line 89, in <module>
    from . import _imaging as core

ImportError: DLL load failed while importing _imaging: The specified procedure could not be found.

Importing Scipy.optimize

In [2]: import scipy.optimize
Traceback (most recent call last):

  File "<ipython-input-2-77fb0d19797b>", line 1, in <module>
    import scipy.optimize

  File "C:\msys64\mingw64\lib\python3.9\site-packages\scipy\optimize\__init__.py", line 413, in <module>
    from ._linprog import linprog, linprog_verbose_callback

  File "C:\msys64\mingw64\lib\python3.9\site-packages\scipy\optimize\_linprog.py", line 22, in <module>
    from ._linprog_highs import _linprog_highs

  File "C:\msys64\mingw64\lib\python3.9\site-packages\scipy\optimize\_linprog_highs.py", line 20, in <module>
    from ._highs._highs_wrapper import _highs_wrapper

ImportError: DLL load failed while importing _highs_wrapper: The specified procedure could not be found.

MustyHickory106 avatar Mar 02 '22 20:03 MustyHickory106

Hey @MustyHickory106, thanks for reporting. This could be happening because Msys2 requires some environment variables set to work and we're not doing that when we start an IPython console with the Msys2 Python interpreter.

This seems a legitimate bug to me, but (unfortunately) it's very fringe (you are the only who have noticed it, as far as I can recall). Since we're busy with other things at the moment and terribly understaffed, we're not going to address it for now, sorry.

ccordoba12 avatar Mar 03 '22 04:03 ccordoba12

Does it work when you import the package name from the console after activating your environment? I ran into this issue myself: https://github.com/spyder-ide/spyder/issues/19220 Edit: it was solved by removing Anaconda paths from the Path environment variable. Maybe this also works for you?

veenstrajelmer avatar Aug 29 '22 08:08 veenstrajelmer

removing the anaconda environment Path variables has removed the problem for me (for now at least), thank you for the recommendation @veenstrajelmer

stjseidel avatar Dec 22 '22 13:12 stjseidel

I also had the same problem and removing conda-specific paths from Path environment variable helped.

mmagnuski avatar May 17 '23 11:05 mmagnuski