I had installed OpenCV, and it was working just fine. But I noticed that a few libraries were missing.
So I decided to install another copy. I moved the working copy to another directory, and started the install of the new one. I was having trouble with this new install, so I cancelled it and moved my old OpenCV install back to its original directory.
But now, my old install doesn't work anymore. Each time I try to run something, it says "ImportError: No module named cv2" or "ImportError: No module named cv" (depending on what was being imported in the file).
What do I do to fix this? I remember encountering a similar issue the first time I installed and ran this copy of OpenCV, and something had to be changed with the Python Path to work correctly. I can't quite remember, and I'm kind of confused about why those settings would change, if they indeed have.
Please let me know what I can do to rectify this. I am using OS X 10.9. Thank you.
UPDATE: I added this to my .bash_profile: export PYTHONPATH=/Users/santosh/opencv-2.4.7/build/lib:$PYTHONPATH. But now when I run opencv samples, I get "Segmentation fault: 11". Any thoughts?
Related
I recently updated Anaconda (Spyder (Python 3.6), Windows 10). Several of my libaries disappeared and had to be re-installed. However, I have been unable to reinstall scipy. When I run "conda install scipy -f" from the Windows PowerShell, scipy seems to be reinstalled. However even if I close Spyder and restat Windows, I continue to get the error: ModuleNotFoundError: No module named 'scipy'.
I know that problems similar to this one have been posted previously, but I have been unable to find anything that seems to fix the problems.
Thanks in advance for any advice (and apologies if this question was posted yesterday as well).
I battled with this same issue. The reason is most likely because you already have a file in the current directory called scipy.py. For example, when I first started with scipy, i made a file literally called scipy.py to practice in. Then, when I tried to import scipy from a different file, the first instance of 'scipy.py' was my practice folder, rather than the actual package which was further into the directory.
I advise you check for folders that you may have named scipy.py that aren't the actual scipy package. I could be wrong, but it seems likely that python will first search the folder it saves your files to, and then trundle over to the packages folder saved elsewhere.
Hopefully this helps some other folks who are stumped by the same issue!
I'm running a code on deep learning, which uses the opencv module, by running python main.py (contains import cv2 statement), but always get the error 'ImportError: dynamic module does not define module export function (PyInit_cv2)'.
I've tried to reinstall my anaconda and create new virtual environments, but all got the same result. This problem really confuses me a lot and I've googled for many related problems, none of them works. I think the problem is something related to the environment and has nothing to do with the code, because I got the same result by simply run import cv2 in python prompt. The more confusing thing is that, even after I remove the opencv module, I also get the same problem, but not a ModuleNotFoundError. Does anyone can give me some advice? Thanks a lot!
I think I found one possible reason of this error.
Recently I was configuring the caffe environment on one server, I downloaded the source code of opencv-2.4.13 and compiled manually, added /usr/local/opencv-2.4.13/build/lib to $PYTHONPATH, and caffe worked well. After that, when I entered one of my virtual environment using conda activate py35, which uses python3.5, tried import cv2 in the python prompt, got the error above.
I'm not sure but I think the cause of the error is opencv-2.4.13 compiles a python2 interface so it can't be imported by python3. Python imports packages by searching the directories listed in sys.path, where $PYTHONPATH is in the second place after the current working directory (This is a great article introduces the mechanism of python finding packages). So when we enter the py35 environment, python will first look for $PYTHONPATH and find the opencv installed on the root directory instead of finding the opencv in the virtual environment using conda install opencv-python.
So there are two solutions of this problem:
Use python2 instead.
Remove /usr/local/opencv-2.4.13/build/lib from $PYTHONPATH.
which all work for me.
Similar post, might help:
ImportError: dynamic module does not define init function (initfizzbuzz)
Could you provide info on how you installed the CV module?
I had the same problem, which was caused by the cv2.so file in /usr/local/lib/python2.7/site-packages/cv2.so. After I deleted the file and use command sudo pip3 install opencv-python, it worked for python3.
I am trying to convert my .py file to an exe file. I've done it in the past but for some reason it isn't working anymore. I am using Python 2.7 and have other versions installed as well but my application won't work without 2.7. If I do python activityKivy.py it runs perfectly. I also tried with py2exe but was unsuccessful, it gave me too many dll warnings and would crash each time I open it. I prefer to stick with pyinstaller because thats what always worked for me. Some help would greatly be appreciates!
error screenshot
**Update: I wasn't able to figure out exactly what the problem was but I was playing around with my environment variables and changing my pip names to pip2 pip3 and thats when this problem started happening and even when I reverted all my changes it still showed me this.I was able to fix it by simply uninstalling pyinstaller and redownloading it.
I am trying to use LBPHfacerecognizer in my python3.6 code.
recognizer = cv2.face.createLBPHFaceRecognizer()
I am aware that face module is in opencv_contrib module. I even uninstalled openCV and installed again with contrib module. I compiled OpenCV with it and python still gives an error which is:
AttributeError: module 'cv2.cv2' has no attribute 'face'
Although in opencv/build/lib I have libopencv_face.dylib, it doesn't compile with python3 and opencv.
I tried everything I can think of but I am running out of ideas.
Any ideas?
edit: Python doesn't give an error when I am working under python3 environment anymore but I still have the same error when I try to run my code in the terminal.
What I am trying to run:
python3 main.py
Any ideas why I have this problem or how I can fix it?
Firstly, the first mistake of mine was after making cmake for few times, I didn't delete old cv2.so file and replace it with new cv2.so.
And it turned out that for working opencv_contrib face module, I have to put this new cv2.so file in the same file that my main.py exists. I don't know if this is the way how should be in the first place. I totally find out this coincidently by myself.
After this, my code worked without any error.
recognizer = cv2.createLBPHFaceRecognizer();
This makes error for me
I tried out, just view the image here.
Try out the code below, it may give you result.
recognizer = cv2.face.LBPHFaceRecognizer_create();
Tl;dr I have been a dummy and messing with those things. I have been going to site_packages doing stuff I shouldn't have been doing and I have messed with my environment variables.... PATH.... PYTHONPATH.... I don't even know all of this stuff yet I have to research it more in depth. Bottom line is that when I'm trying to install a package using a package manager like pip to install opencv... it's installing fine supposedly but then I get the "no module named cv" error.
I tried importing cv and cv2.
I think I am having this problem because I have been messing with a lot of stuff I shouldn't have.
So how do I start a brand new slate?... I don't even know how many python versions I have...