user3479740
user3479740

Reputation: 151

DLL load failed with scipy.optimize?

I'm trying to upload the curve_fit from scipy.optimize to fit an exponential function to some data I have generated. My code looks like:

import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit

When I run the code, I get the following error:

ImportError: DLL load failed: The specified module could not be found.

I have scipy in an Anaconda folder on my computer, and I'm 80% sure I installed it. How do I fix this error? (Or if you have a better way of fitting an exponential function to data, I'm all ears)

Thanks!

edit: Here is the full error:

Traceback (most recent call last):
 File "C:\Users\Casey\Documents\Python\Perc_MatPlot3.py", line 10
    from scipy.optimize import curve_fit
  File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\__init__.py", line 146
    from .optimize import *
  File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\optimize.py", line 35
    from .linesearch import (line_search_BFGS, line_search_wolfe1,
  File "C:\Users\Casey\Anaconda\Lib\site-packages\scipy\optimize\linesearch.py", line 16
    from scipy.optimize import minpack2
ImportError: DLL load failed: The specified module could not be found.

Upvotes: 15

Views: 23163

Answers (5)

Rutger Kassies
Rutger Kassies

Reputation: 64443

Not sure if this is an answer for you, because this error can mean so many things... I've been there...

I just had the same error (also while loading Scipy optimize) just 10 minutes ago with a fresh install of Miniconda for Python 3.3 on a Vista x64 machine. Somehow it failed to add the main Python directory to the Windows PATH (and I'm pretty sure I didn't uncheck the box for it at the end of the installation).

I did the same procedure on some XP and Windows 7 machines earlier this week without any problems, so i caught me a bit by surprise.

If you have no other Python installation on your machine, you can check if running 'python' (type win-key + r, or do it from command prompt) works. If it doesn't, simply add your main installation directory (where python.exe is located) to your PATH variable.

If this doesn't work you could use Dependency Walker to check which DLL the error message is actually about, and then see if that DLL is present somewhere within your PATH or PYTHONPATH.

I have had the same DLL error when multiple versions of the same DLL were compiled with different compilers and the required version wasn't found first. If removing a version (the program it came with) isn't an option, changing the order of your PATH variable can help.

Upvotes: 0

Wey Shi
Wey Shi

Reputation: 1612

I was suffering from exactly the same problem.

from scipy.optimize import minpack2

I reinstalled numpy and MLK but still got this error on Pycharm. I directly update my python to 3.6 and now the problem is solved. During the procedure, use

conda install python=3.6

Since

conda update python

showed me that I already have the 3.5.2, which means conda update failed to update from 3.5 to 3.6 and it is supposed to be capable of upgrading from versions like 3.5.1-->3.5.2 I think. Hope this could help. Plus, remember to reset the environment after the update.

Upvotes: 0

non
non

Reputation: 201

I encountered the error

    from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.

when using cgoehlke's "Unofficial Windows Binaries for Python Extension Packages" for SciPy with a pip3-installed NumPy, overlooking this note:

Many binaries depend on NumPy-1.9+MKL and ...

Their NumPy provides the missing DLLs / modules.

Upvotes: 20

user2751383
user2751383

Reputation: 41

I've run into several problems like this recently when trying to use pyplot and scipy. I have Anaconda 2.7, 32bit running on Windows 7 x64

I just encountered this exact error whilst trying to use curve_fit. I downloaded the 'superpack' from sourceforge: http://sourceforge.net/projects/scipy/

Running this installer fixed the error and didn't affect any other part of my python environment.

Upvotes: 4

Anderson
Anderson

Reputation: 3247

This is most likely you installed 32-bit Python but 64-bit libraries or vice versa.

You need to remove Python and reinstall correct python.

https://www.python.org/download/

Here you can download Python.

Remember you python libraries should be the same 32bit or 64bit as the one of Python.

Upvotes: -2

Related Questions