Scipy ImportError: DLL load failed - python

When I try to get scipy running, the following occurs:
>>> import scipy
>>> from scipy import stats
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from scipy import stats
File "C:\Users\ASUS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages \Python37\site-packages\scipy\stats\__init__.py", line 384, in <module>
from .stats import *
File "C:\Users\ASUS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\stats\stats.py", line 179, in <module>
from scipy.spatial.distance import cdist
File "C:\Users\ASUS\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\scipy\spatial\__init__.py", line 99, in <module>
from .qhull import *
ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.
I have googled the whole day now, but could not figure out a way to solve this problem. I found this question
"ImportError: DLL load failed: The specified module could not be found" when trying to import gensim
and this sums up my whole problem, because I tried the exact same thing:
First, I used pip to install scipy and tried to uninstall and reinstall it.
Then, I also tried scipy version 1.4.1. with the success of being able to import scipy but not scipy.stats
Lastly, I also tried to uninstall numpy+mkl and then reinstall it again, which resulted in: 'Importing the numpy c-extensions failed'
I greatly appreciate any help!

Numpy and scipy rely on lower level fortran libraries such as BLAS and lapack to perform many of their functions. These libraries come in many different versions, including the highly portable ones available from netlib, and other which are optimised for particular systems. In particular, Intel has one called "MKL" - Intel Math Kernel Library. So numpy-mkl just means a version of numpy compiled against the MKL fortran library.
Probably whichever version of numpy you previously had installed was somehow broken, and couldn't find the libraries it needed.

Related

How to import numpy through xlwings package? "ImportError: DLL load failed: The specified module could not be found."

I'm trying to use the 'Run Python' function of xlwings to run Python code through VBA.
I have been using Spyder to execute my code and it runs with no errors.
When trying to run this from VBA with the xlwings package I receive:
"ImportError: DLL load failed: The specified module could not be found."
and this error relates to the numpy package.
I tried uninstalling and reinstalling the anaconda package and using pip install numpy.
I checked that I have the most up to date version of xlwings 0.15.8.
I found this thread https://github.com/xlwings/xlwings/issues/954 stating this issue was fixed with version 0.15.7 of xlwings.
VBA code:
RunPython ("import Demand; Demand.calibrate_Demand()")
Spyder code:
import numpy as np
import xlwings as xw
import pandas as pd
import statsmodels.api as sm
from statsmodels.tsa.arima_model import ARMA
from statsmodels.tsa.arima_model import ARMAResults
from matplotlib import pyplot as plt
import datetime
def calibrate_dDemand():
My Python file is called Demand.py
When executing my VBA code I receive the following error:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "e:\julia\calibration automation\Demand.py", line 17, in <module>
import numpy as np
File "C:\Users\julia\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\__init__.py", line 140, in <module>
from . import _distributor_init
File "C:\Users\julia\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\_distributor_init.py", line 34, in <module>
from . import _mklinit
ImportError: DLL load failed: The specified module could not be found.
If I place import pandas as pd first (before importing numpy) I receive this error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "e:\julia\calibration automation\Demand.py", line 19, in <module>
import pandas as pd
File "C:\Users\julia\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I've been trying for a couple of weeks to hit back against this problem too.
I have a company-owned laptop which is severely restricted to what environment variables I have access too, and PATH is not one of them.
I have no trouble linking Excel with Python (Spyder / Anaconda3 installation), but as soon as add import numpy as np to my python code, I get the same DLL load failed error. (It didn't always do this though, it just started doing it overnight for no reason I can fathom, but I digress). The code itself works fine in Spyder though.
I did eventually find something of a workaround though, but it's a bit of a last resort, being more than a bit awkward and daft. Maybe useful for a developer to track down a more sensible solution though?
Anyway, I found that if I launched Excel from Spyder, the numpy module correctly imports, and remains stable. To do this, I just access the contents of one of the workbook's cells without having Excel already open. This launches Excel, opens the workbooks, and correctly imports numpy.
What do you think?

Problems using webcam in python, openCV

File "C:\Users\Rahul\AppData\Local\Programs\Python\Python36\lib\site-packages\cv2\__init__.py", line 3, in <module>
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
I uninstalled opencv-python and re-installed it again
Ensure that you do not have conflicting versions of numpy in different locations in storage as this seems that the issue is not cv2 but numpy, which is needed when making use of the opencv library

ImportError: cannot import name get_ast_names error on lmfit

I have recently updated to Ubuntu 18.04.1 LTS. After that I tried to run some of my python codes and I got an error related to the lmfit package, here's the code:
import scipy
from asteval import get_ast_names
import lmfit
(I have explicitly added the scipy and asteval modules to check python was finding them porperly)
I obtained this error:
Traceback (most recent call last):
File "/home/maurizio/Documents/Python/Programmini/PhD/TEAS/Test.py", line 3, in <module>
import lmfit
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/__init__.py", line 42, in <module>
from .confidence import conf_interval, conf_interval2d
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/confidence.py", line 12, in <module>
from .minimizer import MinimizerException
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/minimizer.py", line 35, in <module>
from .parameter import Parameter, Parameters
File "/home/maurizio/.local/lib/python2.7/site-packages/lmfit/parameter.py", line 8, in <module>
from asteval import Interpreter, get_ast_names, valid_symbol_name
ImportError: cannot import name get_ast_names
which basically states that lmfit cannot find the function get_ast_names from asteval, although the python interpreter doesn't complain when I try to import it so it should be properly installed.
I have found this question with a similar problem and the guy in the comments claims he solved it by reinstalling it with pip3, so I tried to compile it with python3 and there's no problem so the issue concerns only python 2
Any help?
I believe you must have conflicting versions of lmfit and asteval. This should have been automatically noticed (and ideally resolved) when installing lmfit, but something there appears to have gone wrong. For the latest releases, you should get
>>> import asteval
>>> asteval.__version__
0.9.12
>>> import lmfit
>>> lmfit.__version__
0.9.11
Depending on how you installed these, you may need to check for and remove older versions of asteval in your $HOME/.local/lib/python2.7/site-packages/ folder and re-do pip install asteval.

ImportError: cannot import name 'ellipkm1'

I've seen some answers to my issue, but none seem sufficiently applicable. Here's my issue: I'm by no means a Python expert, but am trying to experiment with a fairly complex Python package. (Don't ask...) When I try to import something I need to move forward, I get the following error (IDLE output):
import scipy.special as special
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
import scipy.special as special
File "C:\DevTools\Python35\lib\site-packages\scipy\special\__init__.py", line 629, in <module>
from .basic import *
File "C:\DevTools\Python35\lib\site-packages\scipy\special\basic.py", line 14, in <module>
from ._ufuncs import (ellipkm1, mathieu_a, mathieu_b, iv, jv, gamma, psi, zeta,
ImportError: cannot import name 'ellipkm1'
My environment:
Windows 10, 64-bit
Python 3.5.1 (64-bit)
Installed packages:
Bottleneck (1.0.0)
numpy (1.10.4)
pandas (0.18.0)
Pint (0.7.2)
pip (8.1.0)
python-dateutil (2.5.0)
pytz (2016.1)
PyYAML (3.11)
requests (2.9.1)
scipy (0.17.0)
setuptools (18.2)
six (1.10.0)
Some were installed via straight 'pip install [package]'; others, because I couldn't get all the necessary C compilers set up on my machine, installed from wheel files from http://www.lfd.uci.edu/~gohlke/pythonlibs/ , as follows:
PyYAML-3.11-cp35-none-win_amd64.whl
pandas-0.18.0-cp35-cp35m-win_amd64.whl
Bottleneck-1.0.0-cp35-cp35m-win_amd64.whl
scipy-0.17.0-cp35-none-win_amd64.whl
Along the way I've had to reverse-engineer failed DLL loads, missing runtime DLLs, etc, but seemingly all of these have now been resolved--yet I still get the darn error above.
Any help would be greatly appreciated. Sorry if I've missed any information that may be helpful in troubleshooting this.
Thanks in advance.
As indicated at the top of Dr. Gohlke's excellent page, he writes
Many binaries depend on NumPy-1.10+MKL ...
and the scipy section states:
Requires numpy+mkl and optionally pillow.
I suspect there's a linking issue hidden somewhere where somebody is trying to call an MKL function and it can't be found, hence the module fails to load. It certainly wouldn't hurt to install the numpy wheel to see if that's the case.
Also, your import can simply be:
from scipy import special

scipy.optimize dll load failure on Windows 8

I am attempting to import scipy.optimize using Python 3.3.1 on Windows 8. I am using scipy-0.12.0. When I attempt to import, Python returns the following error:
>>> import scipy.optimize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python33\lib\site-packages\scipy\optimize\__init__.py", line 146, in
<module>
from .optimize import *
File "C:\Python33\lib\site-packages\scipy\optimize\optimize.py", line 34, in <
module>
from .linesearch import \
File "C:\Python33\lib\site-packages\scipy\optimize\linesearch.py", line 16, in
<module>
from scipy.optimize import minpack2
ImportError: DLL load failed: The specified module could not be found.
I believe this is an operating system error because importing scipy.optimize succeeds when using the same version of Python and scipy on a Windows 7 machine.
I would greatly appreciate any assistance.
Thanks.
It may be a problem with using an incompatible version of Numpy. We solved this problem on a computer at work by using a Numpy-MKL build from Christoph Gohlke's website. This solved our problems on Windows 8 computers, because the builds for Scipy from his website require the Numpy MKL build.
I really encourage you to Install SciPy and NumPy with one these packages:
Python(x,y)
Anaconda
Enthought
Other wise you will end up with all the strange error because these packages mainly based on C libraries that they need to be compiled and usually standard Windows installation doesn't have the right compiler.

Categories

Resources