DLL load failed: The specified module could not be found - python

I have installed Python 3.6.4. When I import cv2, it throws this error:
DLL load failed: The specified module could not be found.
I have OpenCV version 2.4.13.
What should i do?

It's possible that you have Python 2 and 3 installed and Python 3 doesn't know about your opencv installation. Try this:
pip3 install opencv-python
That will install opencv for Python 3 and hopefully that fixes your problem.

Try doing this:
Go to command prompt and "cd" the directory of python.
Enter this if you are running Python 3.x.x
pip3 install opencv-python
OR
2.If on Python 2.x.x
pip2 install opencv-python
DO NOT USE:
pip install opencv
That was my mistake and had to dig a lot to find a solution.

In my situation,
ImportError Traceback (most recent call last)
in ()
10 import os.path
11 from keras.models import load_model
---> 12 import cv2
13 from utils.utils import get_yolo_boxes, makedirs
14 from PIL import Image
ImportError: DLL load failed: The specified module could not be found.
Face this ImportError in the pass week, and I solved with enter below scripts in the Anaconda Prompt.
conda install -c menpo opencv
And here is my environment:
Python 3.6.5 Anaconda
Keras 2.2.2
tensorflow 1.9.0
For more details, here is the log I tried to solved this ImportError:
micky619/holiday-similarity#3

This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
If the problem still persists try using Dependency walker to find out where specifically your problems stem from and then try fixing them individually.
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.

Related

darkflow calls wrong version of python

When trying to use yolo for python I followed https://github.com/thtrieu/darkflow I got flow installed using
pip3 install .
but then, when running
flow --h
I get
File "/home/computername/.local/lib/python3.5/site-packages/darkflow/net/help.py", line 9, in <module>
import cv2
ImportError: No module named 'cv2'
When I call python I get into python 3.6 and if the import cv2 it does not give any problem, i.e., cv2 is imported.
When calling
which python
I get
/home/computername/anaconda3/bin/python
So flow does call the wrong version python. I thought, maybe I should delete the python 3.5 version on my computer, but looking for how to do that I only find warnings that I should not do that.
So my question is: what to do such that it will work?
maybe other relevant information:
which pip3
/usr/bin/pip3
and (I tried to install flow with pip first, but that did not work)
which pip
/home/bombus/anaconda3/bin/pip
I am working on Ubuntu 16.04.3 LTS

After a clean install of OpenCV via pip it throws an ImportError: DLL load failed

After installing OpenCV via pip on Windows 10 with:
pip install opencv-python
I can not import the module. When executing the command:
import cv2
I get the error:
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2__init__.py",
line 7, in
from . import cv2
ImportError: DLL load failed:...
If I look into the file throwing the code, it looks like the following:
import sys
import os
# FFMPEG dll is not found on Windows without this
os.environ["PATH"] += os.pathsep + os.path.dirname(os.path.realpath(__file__))
from . import cv2
sys.modules['cv2'] = cv2
So I guess it is ffmpeg which is missing. Thus I installed ffmpeg like described here: http://www.wikihow.com/Install-FFmpeg-on-Windows
Thus, ffmpeg is in my path. However, the error message still occurs. I also tried to install the ffmpeg via pip with
pip install ffmpeg-normalize
But this did not help either.
The opencv-python Windows packages ship with FFmpeg by default. You can have a look at C:\ProgramData\Anaconda3\lib\site-packages\cv2 and you should find FFmpeg DLL there. You don't have to install it separately.
The real problem lies most probably in Anaconda because they are not shipping python3.dll with their distribution. This is required by PEP 384. Related Anaconda issue is here: https://github.com/ContinuumIO/anaconda-issues/issues/1394
To fix this, you will have to copy python3.dll from a CPython installer package and place it to PATH. The CPython version must match your Anaconda version. Easiest way is to copy the file to some place which is already in PATH. This could be for example C:\Anaconda3 if that's where your Anaconda installation is located.
If the above does not work, make sure that you have Visual C++ redistributable 2015 installed: https://www.microsoft.com/en-us/download/details.aspx?id=48145

Error while import tensorflow module

I try to learn TensorFlow with Python. My problem is with import TF module. Here is my configuration: Python 3.6.1, Windows 7 (with MSVCP140.dll)
I've installed TensorFlow by command (in power shell). It works.
python -m pip install --upgrade tensorflow
But when I run python environment and try import Tensor Flow
import tensorflow as tf
I get errors, this error raise another errors related with it, but at the beginning I want to resolve this first
Traceback (most recent call last): File
"C:\Users\Jacek\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\pywrap_tensorflow.py",
line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_pywrap_tensorflow', [dirname(file)]) File
"C:\Users\Jacek\AppData\Local\Programs\Python\Python36\lib\imp.py",
line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name) ImportError: No module named '_pywrap_tensorflow'
The problem was the cuDNN Library for me - for whatever reason cudnn-8.0-windows10-x64-v6.0 was NOT working - I used cudnn-8.0-windows10-x64-v5.1 - ALL GOOD!
My setup working with Win10 64 and the Nvidia GTX780M:
Be sure you have the lib MSVCP140.DLL by checking your system/path - if not get it here
Run the windows installer for python 3.5.3-amd64 from here - DO NOT try newer versions as they probably won't work
Get the cuDNN v5.1 for CUDA 8.0 from here - put it under your users folder or in another known location (you will need this in your path)
Get CUDA 8.0 x86_64 from here
Set PATH vars as expected to point at the cuDNN libs and python (the python path should be added during the python install)
If you run Windows 32 be sure to get the 32 bit versions of the files mentioned above.
Solution is downgrade Python to version 3.5, and install again TensorFlow. It works for me
This is a known error. There is a file named MSVCP140.DLL, that you will need in your system to run TensorFlow. Check if this file is in your %path%. If it is not, download Visual Studio C++. It is free and you can download it here: https://www.visualstudio.com/vs/cplusplus.
Solution:-
Don't suffer a lot. Simply downgrade your python version from 3.6.1 to 3.5.2 and
install tensorflow again.. you need not to upgrade the package.
"pip install tensorflow" will automatically download latest version (probably
1.0.1)
Steps:-
Step 1:- conda search python
Step 2:- conda install python=3.5.2
Step 3:- pip install tensorflow
Step 4:- import tensorflow as tf
Horray!!.. It works..
Hope you may not get the same error again!!
At first, I used an anaconda environment with Python 3.5 and PIP version 19 but had the same problem. so instead of PIP, I used Conda package manager:
conda install TensorFlow
it worked well after using Conda instead of PIP
If you have a GPU in your system and it is conflicting with the current set of libraries or throwing a cudnn error then you can add the following line in your code to disable the GPU
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
put this in your code and it should be fine.
pip install tensorflow-gpu
Install this package this helps me to solve my issues
or else use python 3.9.7

Error importing python-igraph

I'm trying to install python-igraph package. Installation works without any warning nor error, but then, when I try to import the module, I get an error:
In [1]: import igraph
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-8e950eb5d8d8> in <module>()
----> 1 import igraph
/usr/local/lib/python2.7/site-packages/igraph/__init__.py in <module>()
32 # pylint: disable-msg=W0401
33 # W0401: wildcard import
---> 34 from igraph._igraph import *
35 from igraph._igraph import __version__, __build_date__
36 from igraph.clustering import *
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: /usr/local/opt/gmp/lib/libgmp.10.dylib
Referenced from: /usr/local/opt/glpk/lib/libglpk.36.dylib
Reason: Incompatible library version: libglpk.36.dylib requires version 14.0.0 or later, but libgmp.10.dylib provides version 13.0.0
I can't manage to solve this problem. I saw this post and tried their solutions but it did not work (the problem there was that glpk was not installed, whereas for me it is installed).
To install it I did the following:
brew tap homebrew/science
brew install igraph
sudo pip install python-igraph
And I checked that gmp and glpk were installed with brew install igraph
Does anybody have an idea of how I could manage to install it?
I'm working on Mac os x el capitan, with python2.7
Thanks for your help
Edit from Tamás answer:
I checked, and gmp and glpk do come from homebrew. In fact, /usr/local/opt/gmp is a symlink to <path_to_>Cellar/gmp/6.0.0aand /usr/local/opt/glpk to <path_to_>Cellar/glpk/4.57.
I tried anyway to uninstall igraph (brew uninstall igraph), move somewhere else the files in /usr/local/opt for gmp and glpk, and reinstall igraph. But I get exactely the same error while importing the python module...
It seems like GMP and GLPK are not coming from Homebrew and they are not compatible with each other. You have to fix the installation of GMP and GLPK. Alternatively, you can uninstall igraph, then temporarily move GMP's and GLPK's directories from /usr/local/opt to somewhere else, then install igraph again. igraph will then "think" that GLPK and GMP are not available on your machine and compiles itself without GLPK and GMP support (and disable some features that require GLPK and GMP).
Solved:
Thanks to your comments, I realized that, in fact, Homebrew did not have the last version of gmp.
So, I downloaded the last version from gmp website, and:
uninstalled igraph
installed gmp from the downloaded version
reinstalled igraph
And now it works, I can import the python package!

Importing opencv and getting numpy.core.multiarray failed to import

Trying to install OpenCV and running into an issue where attempting to import cv2 results in this output -
RuntimeError: module compiled against API version 9 but this version of numpy is 7
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import cv2
ImportError: numpy.core.multiarray failed to import
I'm running on Windows 7 x64, Python v 2.7.9
Thanks!
The error is telling you that you have an out of date version of numpy. If you used pip to install things you can simply run pip install numpy -U, or download the appropriate version from their website.
In case
pip install -U numpy
doesn't work (even with sudo), you may want to make sure you're using the right version of numpy. I had the same "numpy.core.multiarray failed to import" issue, but it was because I had 1.6 installed for the version of Python I was using, even though I kept installing 1.8 and assumed it was installing in the right directory.
I found the bad numpy version by using the following command in my Mac terminal:
python -c "import numpy;print numpy.version;print numpy.file";
This command gave me the version and location of numpy that I was using (turned out it was 1.6.2). I went to this location and manually replaced it with the numpy folder for 1.8, which resolved my "numpy.core.multiarray failed to import" issue. Hopefully someone finds this useful!
I had a similar problem and I solved it by downgrading my numpy version.
What I did was:
pip install opencv-python
pip uninstall numpy
pip install numpy=1.18
This has worked for me using
Python 3.7
opencv-python 4.4.0.46
numpy 1.18.0
linux: sudo apt-get install python-numpy
if you are using ubuntu bionic beaver then try running: sudo apt-get install python-numpy
had the same issue, resolve by running the above command.
Hope it helps
In your environment you can try this command:
conda uninstall numpy
conda install -c conda-forge numpy
I use Python 3.7 # RPI 4.
For opencv to install properly I had to install the listed libraries below.
(Not every package was actually installed, after request)
Regarding Numpy, I think one should stick to the latest version.
For me what worked is to uninstall the existing version 1.16.2 and stick with the current stable 1.21.2.
Stackoverflow topic at missing libraries here: ImportError: libcblas.so.3: cannot open shared object file: No such file or directory.

Categories

Resources