Mac Lion: Issue with opencv and python 2.7.5 - python

I tried everything. Installation from source, via homebrew, macports - none of these options work for me. When I type in
import cv2
I get Segmentation fault in the best case scenario, but typically "no module named cv2" error. I followed all possible guides on stackoverflow from people with similar issues and still can't make it work. I have numpy and scipy installed and they are imported properly without any issues.
Could it be that python 2.7.5 (official) is not compatible with opencv at all? After two days of digging I am close to giving up on opencv at all.

This is how I configured it in the end for the official python 2.7.5 from http://www.python.org
First we need to install opencv via brew:
brew tap homebrew/science
brew install opencv
now add /usr/local/Cellar/opencv/2.4.5/lib/python2.7/site-packages to your PYTHONPATH . I did it by editing bash_profile:
open ~/.bash_profile
add this line in TextEditor:
export PYTHONPATH=/usr/local/Cellar/opencv/2.4.5/lib/python2.7/site-packages:$PYTHONPATH
#Check the version in your directory
Save the file and do:
source ~/.bash_profile
Now everything should be ready.

Related

Importing the numpy c-extensions failed

Importing the numpy c-extensions failed
I installed python 3.7 on my windows system to work on visual studio code. Everything was going well, including using the libraries.
I uninstalled python using the uninstalling program tool in control panel. And installed Miniconda 3.
I checked that everything works well, and then installed the numpy library using conda install numpy in my terminal GitBash on windows 10, then checked it on my visial studio code, but it failed to start.
Reproducing code example:
import numpy as np
A = np.array([[-1], [7], [-26]])
Error message:
Traceback (most recent call last): File
"C:\Users\ramim\Miniconda3\lib\site-packages\numpy\core__init__.py",
line 17, in
from . import multiarray File "C:\Users\ramim\Miniconda3\lib\site-packages\numpy\core\multiarray.py",
line 14, in
from . import overrides File "C:\Users\ramim\Miniconda3\lib\site-packages\numpy\core\overrides.py",
line 7, in
from numpy.core._multiarray_umath import ( ImportError: DLL load failed: Не найден указанный модуль.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"c:/Users/ramim/Desktop/22/Matrix library/alsf.py", line 3, in
import numpy as np File "C:\Users\ramim\Miniconda3\lib\site-packages\numpy__init__.py", line
142, in
from . import core File "C:\Users\ramim\Miniconda3\lib\site-packages\numpy\core__init__.py",
line 47, in
raise ImportError(msg) ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\Users\ramim\Miniconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.17.3" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
If you're working with a numpy git repository, try git clean -xdf (removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: Не найден указанный модуль.
Numpy/Python version information:
Python 3.7.5
Numpy 1.17.3
I tried to uninstall and install the numpy library again, but it was useless.
Note: when I type in the teminal conda install numpy, it says:
All requested packages already installed
That's how I checked if numpy is really installed!
How to solve that?
Try to uninstall numpy and setuptools first:
pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
Borrowed from solution provided by mehdiHadji here- https://github.com/ipython/ipyparallel/issues/349
Not sure this is a thing in Visual Studio too, but for Eclipse I had to change one of the environmental variables.
Setup: Windows, Python 3.7, Conda venv with numpy
Solution:
CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
For Eclipse, the environment variables can be accessed via Properties -> Run/Debug Settings -> Edit -> Environment.
Anaconda also documented the fix, albeit for a different problem:
Conda Troubleshooting
Similar with my problem recently. I'm using Python 3.8 by Miniconda on Win 10 system. I solved the problem by changing default terminal from PowerShell to Command Prompt.
Steps:
Open VS Code's Command Palette menu by pressing Ctrl+Shift+P or F1
Choose "Terminal: Select Default Profile" entry
Then pick "Command Prompt" option
Restart VS Code
This issue is caused by VScode default terminal (powershell) setting,
To switch VScode default terminal from powershell to cmd, the conda env will be activated correctly, other powershell will try to invoke conda activate xxxxxx which will fail, then the subsequent import numpy will fail.
So two ways to fix it:
Fix path search issue under powershell environment to get conda activate xxxxxx successfully executed;
Change vs code default terminal to 'cmd':
add "terminal.integrated.shell.windows": "C:\Windows\System32\cmd.exe" in settings.json
I solved this by the following steps-
Uninstalling numpy and pandas with conda
Installing numpy and pandas with pip
I solved the problem by reinstalling NumPy through pip:
pip install --upgrade --force-reinstall numpy
I solved it by removing ALL numpy versions
pip uninstall numpy
pip3 uninstall numpy
And then installing numpy and libatlas-base-dev via apt-get
sudo apt-get remove python3-numpy
sudo apt-get install libatlas-base-dev
It looks like there's something wrong with your %PATH%. It might either contain some conflicts, or just be too long (>2047 chars). Try adding the folder with the dlls (from the environment you're trying to use) to the very beginning of it:
PATH=C:\Users\ramim\Miniconda3\Library\bin;%PATH%
python -c "import numpy"
(based on this)
For those scratching their head wondering why re-installing numpy module works:
If you are using a virtual environment (say in a relative location called env), make sure that folder does not make it to other platforms like Docker, or different OS you might be switching to.
Remember the compilation of Python and C extensions necessary for numpy are platform dependent. So if it works in Windows, it will not work in Linux using the same virtual environment (cached modules).
For example, this is particularly important if you are running your code on Windows - and then try to run it on a Linux container via Docker Desktop. (Make sure env - or whatever your virtual env is called - is ignored and not copied onto the container)
I had the same problem, and tried several of the solutions given here, but none worked for me. I looked in another forum and was able to solve the problem (https://github.com/numpy/numpy/issues/13252):
conda uninstall numpy
pip3 install numpy.
This issue is still ongoing. I use VS code with conda venv, and solved it in a similar way with marineCoder:
In addition to numpy and pandas, I also remove matplotlib using conda uninstall
Cautiously reinstall pandas and numpy using pip install
In my case, the error shows up whenever matplotlib package is installed, so I got to either remove it or downgrade the three of them. There is a clash on numpy dependency. Another related issue is shown in this post:
I get `No module named _multiarray_umath` when using matplotlib
In my case, I had to manually 'conda activate myenv' the desired environment in the VS code terminal. Previously, I only had to select the python version from the desired environment, and then the environment would auto-activate. This answer references and confirms Brett Cannon's comment above, which was the sole reason I thought to try it.
As I'm on MacOS (with an M1 CPU) I realize my answer is not exactly an answer to the poster's question but as I got the same error and Google sent me here perhaps this helps someone.
In my case I found the error was caused because VSCode was still running in Intel-X86 mode on my Mac-M1. Simply re-installing VSCode using the latest "Mac Universal" distribution switched it to ARM64 mode fixing the issue for me.
Uninstalled anaconda and installed latest version
I tried the answers here but they didn't work for me, uninstalled older version of anaconda (don't remember previous version number now) and installed Anaconda3-2022.05 (Anaconda Navigator 2.1.4). This sorted it for me. I hadn't used my anaconda setup in long time and thus didn't care if my preinstalled packages get wiped out. This took a lot less time and saved from pain of trying more approaches.
OS: Windows 10
Please check both of these (your PATH or PYTHONPATH environment variables) carefully to see if they are what you expect.
In my case, there was an issue related to updated versions of python and NumPy, I resolved both problems by running a single command over conda PowerShell prompt i.e. conda update --all
Here are the steps-
Open Anaconda Powershell Prompt and click 'run as Administrator'.
Enter the following code into the prompt and click enter: conda update --all ...
You are all set to run your script
I hit this error while running a block of code in a .ipynb Jupyter Notebook file.
I fixed the problem by switching the version of Python that was running. Specifically, I was running Python 3.8.5 from the Anaconda3 directory on my computer and I switched this to Python 3.9.2 that I had installed elsewhere on my computer.
To toggle the version of Python in VSCode while working on a .ipynb file, click on the version specified in the top-right corner of the screen. Thereafter, a dropdown menu will allow you to select from different versions of Python installed on your computer.
For my situation, I had updated the version of python that I was using. Running git clean -xdf resolved the issue.
My system:
OS: Mac OS 11.6
Python: 3.7.8 => 3.8.12
Numpy: 1.20.2
Poetry: 1.1.6

problem installing and importing modules in python

I am installing python on windows10 and trying to install the opencv and numpy extentions in the command window. I get no error installing them and it says it is successfully installed. But when I try to check the installation and import cv2 it does not recognize it and give me the error: no module named cv2.
can anybody help me with this problem? Is there something wrong in installation process or do I need to install something else?
I checked the newest version of each and used the compatible one with my system.
Thanks.
One solution could be that you have 2 versions of python. So, go to the specific python's scripts directory and run: pip install numpy
If that too doesn't work, you can find the answers to this question on Why can't I import opencv3 even though the package is installed?, as stated by #Cut7er.
I have tried the solutions given to the above stated question myself also. But, they didn't work for me. So, another thing that you could try to use is this IDE called PyCharm. It ofcourse is much more beautiful that the IDLE, but it also has an inbuilt GUI controlled installation of binaries or packages. That would make things a lot easier. I have faced a lot of issues with packages for python and this IDE made things a lot easier. You can find it on https://www.jetbrains.com/pycharm/download/#section=windows.
You can also use anaconda. But, I found it a little difficult to use since, it has similar issues.
EDIT:
Seems like you are using PyCharm. But, you are installing libraries from your command prompt. So, see the answer to: ImportError: No module named 'bottle' - PyCharm. This answer guides you through how to install a certain library through your PyCharm window itself. So,
1) Go to Files>Settings
2) Search for "Interpreter" from the searching tab. Open the interpreter
3) You can now see a plus sign on the right. A click on it will open up a section on the left.
4) In the searching tab, search for numpy or opencv. Click on whichever module you want to install. And then click on the "install package" button on the bottom left. This will install the package for you.
5) Then click save. And run your file that says import cv/cv2.
This should probably do the trick.
Hope it helps!
Is it possible that you have 2 versions of python on your machine and your native pip is pointing to the other one? (e.g. you pip install opencv which installs opencv for python 2, but you are using python 3). If this is so, then use pip3 install opencv
I removed the Anaconda version on my machine, so I just have python 3.7 installed. I removed the python interpreter(Pycharm) and installed it again and the problem got fixed somehow!
I suspect you have two versions of python and the one you're using doesn't have opencv on it, because pip pointed to the wrong one.
A pragmatic solution assuming you're using the python version with conda is to just use conda to install cv2:
conda install -c menpo opencv
A more careful solution is to figure out how to get the pip that points to the python version you're using. On linux I can check that my pip points to my python like this:
:~$ which python
/home/kpierce/anaconda3/bin/python
:~$ which pip
/home/kpierce/anaconda3/bin/pip
So you see the pip and python versions are associated. On windows I suspect you do an analogous thing on the command line like
where python
where pip
And if they don't match, you might try
where python
where pip3
to see if those match. You need to use the pip that points to the correct python version. You can view the python version by entering the python interpreter and running
import sys
sys.version

DLL load failed error when importing cv2

I have installed opencv on my windows machine using python 3.6 without any issues, using:
pip install opencv-python
but when I try to import cv2 I get the following error
ImportError: DLL load failed: The specified module could not be found.
I have seen this post
It says cv2 doesn't work with python 3 I was wondering if this has been fixed or if there is a way around it
I took a lot of time to solve this error!
Run command
pip install opencv-contrib-python
You can download the latest OpenCV 3.2.0 for Python 3.6 on Windows 32-bit or 64-bit machine, look for file starts withopencv_python‑3.2.0‑cp36‑cp36m, from this unofficial site. Then type below command to install it:
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win32.whl (32-bit version)
pip install opencv_python‑3.2.0‑cp36‑cp36m‑win_amd64.whl (64-bit version)
I think it would be easier.
Update on 2017-09-15:
OpenCV 3.3.0 wheel files are now available in the unofficial site and replaced OpenCV 3.2.0.
Update on 2018-02-15:
OpenCV 3.4.0 wheel files are now available in the unofficial site and replaced OpenCV 3.3.0.
Update on 2018-06-19:
OpenCV 3.4.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.0.
Update on 2018-10-03:
OpenCV 3.4.3 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support, and replaced OpenCV 3.4.1.
Update on 2019-01-30:
OpenCV 4.0.1 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
Update on 2019-06-10:
OpenCV 3.4.6 and OpenCV 4.1.0 wheel files are now available in the unofficial site with CPython 3.5/3.6/3.7 support.
Update on 2023-02-11:
OpenCV 4.5.5 wheel files are now available in the unofficial site with CPython 3.7/3.8/3.9/3.10/3.11 support.
If you are using Anaconda with python 3.5, this is a problem in the Anaconda release. (Refer this issue)
You can fix this issue by copying python3.dll file to Anaconda3 folder (where python.exe is located)
How to get "python3.dll"
In cmd, type python --version to find whether your installation is 64-bit or 32-bit
download python 3.x embeddable zip file from here
Extract the zip file and copy python3.dll file to Anaconda3 folder
But if you can move to Anaconda with python 3.6 you will not face this issue. If it is possible for you, then it is the recommended way..
Recently I have faced the similar issue in Azure Windows Server 2012 r2 . Tried all option with and without Anaconda but none of them helped. After lot of findings I found that mfplat.dll was missing which is related to Window Media Service.
Hence you have to manually install the features so that you can get dll related to window media service.
1.Turn windows features on or off
2.Skip the roles screen and directly go to Feature screen
3.Select "Desktop Experience" under "User Interfaces and Infrastructure"
After this all required dll of media services for opencv would be available.
So if you are planning to run your code in cloud(Window Server) then please dont forget to select Desktop Experience feature.
I ran into this problem on Windows 10 (N) with a new Anaconda installation based on Python 3.7 (OpenCV version 4.0). None of the above advice helped (such as installing OpenCV from the unofficial site nor installing VC Redistributable).
I checked DLL dependencies of ...\AppData\Local\conda\conda\envs\foo\Lib\site-packages\cv2\cv2.cp37-win_amd64.pyd using dumpbin.exe according to this github issue. I noticed a library MF.dll, which I figured out belongs to Windows Media Foundation.
So I installed Media Feature Pack for N versions of Windows 10 and voilà, the issue was resolved!
After spending too much time on this issue and trying out all different answers, here is what found:
The accepted answer by #thewaywewere is no longer applicable. I think this was applicable when opencv-python module still wasn't available.
This is indeed a bug in Anaconda 4.2 because they forgot to ship python3.dll. They have fixed this in next releases but unfortunately 4.2 is the last release with Python 3.5 as default. If you are stuck with Python 3.5 (for example VS2015 is only aware of versions up to 3.5) then you must manually download python3.dll as described in answer by #Ramesh-X.
If you can move on to Python 3.6 (which at present bit difficult if you are using OpenCV and VS2015) then just install latest Anaconda version and you don't have to deal with any of these.
There are many questions on that and many suggestions. None of them helped me for the recent Opencv 3.4.16 and Python 3.6/3.7.
Finally I switched to Pyhon 2.7.15 and installed opencv 3.1.0. The DLL-problem was solved.
When I look in cv2.pyd with dependency walker, the 3.1 has no dependency to one missing dll. Opencv 3.4 has this missing dependency to this dll:
API-MS-WIN-DOWNLEVEL-SHLWAPI-L1-1-0.DLL
may be this is the problem.
P.S.: I have Win7 pofessional 64Bit, 32Bit Python 2.7.15
Frankly there are a lot of very smart and complicated answers here. Mine is dumb and simple. I deleted my conda environment, re-installed from scratch, taking pains to install opencv first. This fixed my problems. Environments are meant to be temporary and diaphanous -- don't get too attached.
So if my environment was called fubar first make sure every instance is deactivated (including any IDEs that are using it). Then remove it:
conda remove --name fubar --all
Now I simply recreate my environment and add opencv first:
conda create --name fubar
conda activate fubar
conda install opencv
And then go from there. First open python and make sure import cv2 works. Then you should be on your way. Note I always (always) install Spyder last as it tends to screw things up when I don't.
Note, if that doesn't work, we have had some cases where people have to uninstall and reinstall Anaconda, and then things worked. Obviously a last resort.
In my case a major update of Windows 10 removed some Windows packages, so other methods (reinstalling opencv etc.) did not help. To fix it, install:
a) Microsoft Visual C++ Redistributable for Visual Studio 2015, 2017 and 2019
b) Media Feature Pack for N versions - needed only if you have Windows 10 N
Both need restart of PC.
I had the same issue when installing opencv 2.4.13 on Anaconda3 (Python 3.6)... I managed to fix this issue by reverting to Anaconda2 (Python 2.7)
this happens because the compiler or the interpreter is finding more than one package of the file, delete all the number of same package you have and then keep only one and then try to install. It serves
The issue is due to the missing python3.dll file in Anaconda3.
To fix the issue, you should simply copy the python3.dll to C:\Program Files\Anaconda3 (or wherever your Anaconda3 is installed).
You can get the python3.dll by downloading the binaries provided at the bottom of the Python's Release page and extracting the python3.dll from the ZIP file.
I had the same issue with python 3.6(Anaconda3) and OpenCV 3.4.1 for spyder to work. Even after copying cv2.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages, it didn't work.
But found a solution
Later I installed OpenCV and Dlib on Anaconda and copied the generated cv2.cp36-win_amd64.pyd and dlib.cp36-win_amd64.pyd into Anaconda3 Users/home/Anaconda3/Lib/site-packages. These can be copied from environment folder C:\Users\home\Anaconda3\envs\opencv\Lib\site-packages.
Finally spyder started to work
I managed to get it to work by installing python 3.9.12 in a new environment (using conda), and then installing opencv in that environment. Because of my python version, opencv version 4.5.5 was installed instead of version 4.60.
(I had already updated VC2015-2022 and added the python3.dll to PATH; neither of these worked.)
I have the same problem. when I install WinPython programming, and run opencv after copy the cv2.pyd file from my opencv directory, it will be like this: C:\Users.....\Downloads\opencv\build\python\2.7\x64, x64 or x86 is depend on your 32 or 64 bit devices. and paste to C:\Users.....\Downloads\WinPython-64bit-3.5.4.1Qt5\python-3.5.4.amd64\Lib\site-packages, I prefer the previous python 3.5 than 3.6. Because when I "import cv2" installed (python 3.6) it shows directly: "ImportError: DLL load failed: The specified module could not be found"
Then I install python 3.5 and open WinPyhton Command prompt and type "pip install opencv-python".
The command prompt download opencv automatically, it shows the process like this "Successfully installed opencv-python-3.3.0.10"
Finally, I try to run open cv by type "import cv2", it works
i try to type "cv2.version", and shows: '3.3.0'
Under Winpython : the Winpython-64bit-.../python_.../DLLs directory the file cv2.pyd should be renamed to _cv2.pyd
(base) C:\WINDOWS\system32>conda install C:\Users\Todd\Downloads\opencv3-3.1.0-py35_0.tar.bz2
I ran this command from anaconda terminal after I downloaded the version from
https://anaconda.org/menpo/opencv3/files
This is the only way I could get cv2 to work and I tried everything for two days.
If this helps someone, on official python 3.6 windows docker image, to make this thing work I had to copy following libraries from my desktop:
C:\windows\system32
aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dmenterprisediagnostics.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mf.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msacm32.drv
msvfw32.dll
ngcrecovery.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
WpAXHolder.dll
wuceffects.dll
C:\windows\SysWOW64
aepic.dll
avicap32.dll
avifil32.dll
avrt.dll
Chakra.dll
CompPkgSup.dll
CoreUIComponents.dll
cryptngc.dll
dcomp.dll
devmgr.dll
dsreg.dll
edgeIso.dll
edpauditapi.dll
edputil.dll
efsadu.dll
efswrt.dll
ELSCore.dll
evr.dll
ieframe.dll
ksuser.dll
mfasfsrcsnk.dll
mfcore.dll
mfnetcore.dll
mfnetsrc.dll
mfplat.dll
mfreadwrite.dll
mftranscode.dll
msacm32.dll
msvfw32.dll
oledlg.dll
policymanager.dll
RTWorkQ.dll
shdocvw.dll
webauthn.dll
wuceffects.dll`
Please Remember if you want to install python package/libraries for windows,
you should always consider Python unofficial Binaries
Step 1:
Search for your package, download dependent version 2.7 or 3.6 you can find it under Downloads/your_package_version.whl its called python wheel
Step 2:
Now install using pip,
pip install ~/Downloads/your_packae_ver.whl
this will install without any error.
I had the same problem and spent 3 full days wrestling with it. I tried everything suggested: upgrading pip, updating Visual C++, updating Anaconda, manually downloading files and basically every solution I could find on the web. Here's what finally worked maybe it'll help someone else:
1- I ditched Python 3 and Anaconda-based downloads since I noticed they had several problems and downloaded Python 2.7.16 64-bits instead.
2- Navigated to where Pip was located on my drive (for me the path is C:\Python27\Scripts) highlighted the path by selecting it, and typed "cmd" then enter so the Command Prompt opens on that path (I noticed skipping this usually brings about a couple errors)
3- Updated Pip using python -m pip install --upgrade pip on the CMD (again, skipping this and not updating it didn't let this procedure go through)
4- Downloaded the appropriate Wheel file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv (after trying several the one that worked for me was opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl) I copy-pasted it to the same folder Pip was in (C:\Python27\Scripts for me) and then installed it through CMD using: pip install opencv_python-2.4.13.7-cp27-cp27m-win_amd64.whl. Always through CMD opened on that path as showed in step 2
5- After step 4 when I imported OpenCV using import cv2 I didn't have the DLL error anymore but an error related to numpy (since I had just installed that version of Python and so Numpy wasn't installed yet). I installed numpy by typing pip install numpy and voilà ! The problem was solved and OpenCV imported correctly.
Hope this helps someone.
In my case, I had to install an older version of openCV (windows 10, Python 3.6.8)
pip install opencv-python==3.3.0.9
This error can be caused by missing the following dll
To have this dll install:
https://www.microsoft.com/en-us/software-download/mediafeaturepack
as already explained above
Running python 3.8.8 from windows 10 powershell from an anaconda 4.10.1 environment I installed opencv with
conda install opencv
I could import opencv no problem when I launched python from the command line.
However, when I tried to run code from inside pydev using the python interpreter for the specific anaconda environment I had activated, pydev couldn't find whichever dll it was looking for when importing opencv.
Setting the following environment variable resolved the issue:
CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1
Source: PyDev/Eclipse not loading _mklinit when run from a Conda environment
Which points to this trouble shooting description for a different library loading issue: https://docs.conda.io/projects/conda/en/latest/user-guide/troubleshooting.html#numpy-mkl-library-load-failed
If you are using a server or docker enviroment without a gui (e.g. Windows Core Server) make sure that you use the headless version of cv2:
pip install opencv-contrib-python-headless
I had the same problem, it seems openCV requires Windows Media Feature pack which is not installed on Windows 10 N by default, please install it using the following link:
https://www.microsoft.com/en-us/software-download/mediafeaturepack
Windows 11 N
This a final fix for the people who don't use anaconda.
simply there are missing DLL files, that's it
download the latest version of
https://sourceforge.net/projects/opencvlibrary/
Then after you extract it search for .dll files and copy all of them and paste into C:\Windows\System32 and approve for replacing.
That's it !
Install python using:
pip install opencv-python(It will take the latest version)
Make sure opencv-python is installed in path(\Python\Python36\Lib\site-packages),
you will find cv2 folder over there.
To check the version of cv2:
import cv2
print(cv2.__version__)

pyexiv2 with homebrew python 2.7.4

I have just installed python (2.7.4) with brew on my macbook pro (10.7.5).
I also installed exiv2 and pyexiv2 with brew.
When I import pyexiv2 from the python interpreter, I got the following error :
Fatal Python error: Interpreter not initialized (version mismatch?)
What I should do to correct that (considering that I do not want to remove the brewed python as suggested in this thread:
How to install python library Pyexiv2 and Gexiv2 on osx 10.6.8?)
Thanks a lot for any advice !
After much searching and looking at a few complicated solutions across the web, I found a simple method to solve this problem, in the Homebrew wiki itself!
The root of the problem is the boost dependency library, which by default links to the system python and not a brewed python, from the wiki:
Note that e.g. the boost bottle is built against system python and should be brewed from source to make it work with a brewed Python. This can even happen when both python executables are the same version (e.g. 2.7.2). The explanation is that Python packages with C-extensions (those that have .so files) are compiled against a certain python binary/library that may have been built with a different arch (e.g. Apple's python is still not a pure 64bit). Other things can go wrong, too. Welcome to the dirty underworld of C.
(emphasis mine)
So first uninstall the dependency libraries and pyexiv2 itself with:
brew rm $(brew deps pyexiv2)
brew rm pyexiv2
Then install boost from source as indicated here:
brew install boost --build-from-source
Note: building boost might take time, so be patient, it took my system 27.9 mins! (output below)
usr/local/Cellar/boost/1.54.0: 9865 files, 568M, built in 27.9 minutes
Then reinstall pyexiv2 and dependencies:
brew install pyexiv2
That's it, now importing pyexiv2 should work flawlessly.
Check which Python you are running (which python), and run python with the -v option to see where it is looking for modules. Check that all those things match your expectations. Then run brew doctor, and if that doesn't complain about anything, report a bug.
I had a bunch of trouble installing pyexiv2 with Homebrew on macOS Sierra using bool.dev's answer above. The Homebrewed pyexiv2 kept throwing a Segmentation Fault 11 on import.
I eventually got it installed and working with the Homebrewed Python by modifying bool.dev's answer with the following commands:
brew install boost --build-from-source
brew install boost-python
brew install exiv2
sudo pip install git+https://github.com/escaped/pyexiv2.git
I found the last line in the following document on Page 30 after getting sucked down a Google hole.
Hope this helps!

opencv and python in osx - but how?

I tried to install opencv and python with port and brew.
but when i try import cv it says "module not found".
i have the same problem on my windows machine and just no solution works.
is there a simple step by step solution for someone who does not know all the terminal codes?
im not really a good programmer but it would be awsome to get this working.
--edit--
got it working on Windows and Mac
Mac: First uninstalled Homebrew and MacPort
restarted, installed Macport again.
then :
sudo port install opencv +universal +python26
after that i just had to install numpy.
Win7
installed
python-2.7.2.msi
OpenCV-2.2.0-win32.exe
opencv-python-2.2.0.win32-py2.7.exe
numpy-1.6.0-win32-superpack-python2.7.exe
When using brew, try brew info opencv, which explicitly tells you:
The OpenCV Python module will not work until you edit your PYTHONPATH like so:
export PYTHONPATH="/usr/local/lib/python2.6/site-packages/:$PYTHONPATH"
The export thing should go into your shell config. You could put this into ~/.bashrc, but the truly system-wide setting would need to be set otherwise (try Setting environment variables in OS X?).
Or else, in your python script:
import sys
sys.path.insert(0, "/usr/local/lib/python2.6/site-packages/")
import cv
Then it should work.
Easiest way (imo) is using macports - once you did setup macports, installing opencv with python is:
port install opencv +python27
(you may need to uninstall opencv first if you already installed it without python support), Then use macport's python (not the system one) - should be in /opt/local/bin/python2.7, you can add that to your path so you don't need to type the full one.

Categories

Resources