15

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.
user3479740
  • 151
  • 1
  • 1
  • 5
  • Either it isn't installed correctly, or scipy is not in your pythonpath, because that import should work. Can you import scipy at all, or is it just scipy.optimize? – pseudocubic Mar 31 '14 at 14:29
  • Please post the _full_ error. Are you sure you are running the correct version of python? Have you tried reinstalling? I have adjusted your tags because this is unrelated to matplotlib, but definitely a windows issue. – tacaswell Mar 31 '14 at 14:30
  • I had no problems with "import scipy" but my code as written produced the error – user3479740 Mar 31 '14 at 14:48

5 Answers5

20

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.

non
  • 201
  • 2
  • 2
  • Occurred importing scipy.special in one of my own libraries. Works fine in Spyder, but when I try idle - ouch. Please post more on how to install MKL. – Colin Helms May 08 '19 at 05:28
4

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.

0

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.

Chris Mack
  • 5,148
  • 2
  • 12
  • 29
Rutger Kassies
  • 61,630
  • 17
  • 112
  • 97
0

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.

Wey Shi
  • 1,552
  • 1
  • 9
  • 15
-2

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.

Anderson
  • 3,139
  • 3
  • 33
  • 45