I am facing issues while installing OpenCV package on Mac Sierra (10.12.1)
I followed all the steps mentioned in the link :
http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/
I got issues related to QTKit.h file not being present. This is a known issue and so I followed several solutions but none worked.
I then followed all possible solutions present here :
https://github.com/opencv/opencv/issues/6913
&
http://stackoverflow.com/questions/39590741/fatal-error-qtkit-qtkit-h-file-not-found-when-i-build-opencv-on-mac
But none of them seem to work (or so I guess)
I cannot see the location where OpenCV has been installed.
I did try to check in the TERMINAL by doing an import and it works without issues.
IMPORT CV2
But when I run my code on the python IDE (PyCharm), I get the error for CV2 module not found.
I also tried searching in Pycharm's IDE if I could see a CV2, but i couldn't.
Please help!
I ran into the same issues installing OpenCV with Python 2.7 following Adrian's tutorial on pyimage. I got around the issue with compiling on macOS Sierra by switching to the ‘pr7266’ branch for opencv and switching to the ‘master’ branch for opencv_contrib
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git fetch https://github.com/opencv/opencv.git +pull/7266/head:pr7266
$ git checkout pr7266 # instead of 3.0.0 or 3.1.0
See instructions at - https://github.com/opencv/opencv/pull/7266
I've never used PyCharm before so can't help there, hope this helps though!
I have a situation very much like the one at Error "ImportError: DLL load failed: %1 is not a valid Win32 application", but the answer there isn't working for me.
My Python code says:
import cv2
But that line throws the error shown in the title of this question.
I have OpenCV installed in C:\lib\opencv on this 64-bit machine. I'm using 64-bit Python.
My PYTHONPATH variable: PYTHONPATH=C:\lib\opencv\build\python\2.7. This folder contains cv2.pyd and that's all.
My PATH variable: Path=%OPENCV_DIR%\bin;... This folder contains 39 DLL files such as opencv_core246d.dll.
OPENCV_DIR has this value: OPENCV_DIR=C:\lib\opencv\build\x64\vc11.
The solution at Error "ImportError: DLL load failed: %1 is not a valid Win32 application" says to add "the new opencv binaries path (C:\opencv\build\bin\Release) to the Windows PATH environment variable". But as shown above, I already have the OpenCV binaries folder (C:\lib\opencv\build\x64\vc11\bin) in my PATH. And my OpenCV installation doesn't have any Release folders (except for an empty one under build/java).
What's going wrong? Can I tell Python to verbosely trace the loading process? Exactly what DLL files is it looking for?
I noticed that, according to http://www.dependencywalker.com/, the cv2.pyd in C:\lib\opencv\build\python\2.7 is 32-bit, whereas the machine and the Python I'm running are 64-bit. Could that be the problem? And if so, where can I find a 64-bit version of cv2.pyd?
Unofficial Windows Binaries for Python Extension Packages
You can find any Python libraries from here.
Please check if the Python version you are using is also 64 bit. If not then that could be the issue. You would be using a 32-bit Python version and would have installed a 64 bit binaries for the OpenCV library.
Wow, I found yet another case for this problem. None of the above worked. Eventually I used python's ability to introspect what was being loaded. For Python 2.7, this means:
import imp
imp.find_module("cv2")
This turned up a completely unexpected "cv2.pyd" file in an Anaconda DLL directory that wasn't touched by multiple uninstall/install attempts. Python was looking there first and not finding my good installation. I deleted that cv2.pyd file and tried imp.find_module("cv2") again and python immediately found the right file and cv2 started working.
So if none of the other solutions work for you, make sure you use Python introspection to see what file Python is trying to load.
In my case, I have 64-bit Python, and it was lxml that was the wrong version--I should have been using the x64 version of that as well. I solved this by downloading the 64-bit version of lxml here:
https://pypi.python.org/pypi/lxml/3.4.1
lxml-3.4.1.win-amd64-py2.7.exe
This was the simplest answer to a frustrating issue.
I just had this problem. It turns out it was just because I was using an 64-bit version of the OpenCV file. I tried the x86 and it worked.
I had the same problem. Here's what I did:
I downloaded the pywin32 wheel file from here, then
I uninstalled the pywin32 module. To uninstall, execute the following command in a command prompt.
pip uninstall pywin32
Then, I reinstalled pywin32. To install it, open the command prompt in the same directory where the pywin32 wheel file lies. Then execute the following command.
pip install <Name of the wheel file with extension>
Wheel file will be like: piwin32-XXX-cpXX-none-win32.whl
It solves the problem for me.
I copied cv2.pyd file from /opencv/build/python/2.7/x86 folder instead of from /x64 folder to C:/Python27/Lib/site-packeges. I followed rest of the instructions provided here.
Added by someone else, not verified: I also copy file cv2.pyd to folder C:/Python27/Lib/site-packages/cv2. It works.
For me the problem was that I was using different versions of Python in the same Eclipse project. My setup was not consistent with the Project Properties and the Run Configuration Python versions.
In menu Project → Properties → PyDev, I had the Interpreter set to Python 2.7.11.
In Run Configurations → Interpreter, I was using the Default Interpreter. Changing it to Python 2.7.11 fixed the problem.
If your build system (CMake in my case) copies the file from <name>.dll to <name>.pyd, you will get this error if the original file wasn't actually a DLL file. In my case, building shared libraries got switched off, so the underlying file was actually a *.lib.
I discovered this error by loading the pyd file in Dependency Walker and finding that it wasn't valid.
Update NumPy.
pip install numpy --upgrade
It works for me!
This one worked for me:
pip install -- pywin32==227
I faced the same issue when I uninstalled and reinstalled a different version of 2.7.x of Python on my system using a 32-bit Windows Installer. I got the same error on most of my import statements.
I uninstalled the newly installed Python, downloaded a 64-bit Windows installer, reinstalled Python again, and it worked.
So I had problems installing vtk under Windows (as I use Python 3.7, there isn't any binary available so far. Just for older Python versions pip install vtk is not working)
I did wrote Python in my cmd:
Python 3.7.3 on win32
So I now know I have Python 3.7.3 running on a 32 bit.
I then downloaded the correct wheel at VTK‑8.2.0‑cp37‑cp37m‑win32.whl
Next I installed that wheel:
pip install VTK-8.2.0-cp37-cp37m-win32.whl
Then I tested it and it worked:
python
import vtk
I experienced the same problem while trying to write code concerning speech-to-text.
The solution was very simple. Uninstall the previous pywin32 using the pip method:
pip uninstall pywin32
The above will remove the existing one which is by default for 32 bit computers. And install it again using
pip install pywin32
This will install the one for the 64 bit computer which you are using.
I had a similar issue while trying to run uvicorn,
Creating a new virtual environment and reinstalling the python packages worked
You can install opencv from official or unofficial sites.
Refer to this question and this issue if you are using Anaconda.
It has a very simple solution.
After installing opencv
place
cv2.pyd from C:\opencv\build\python\2.7\ **x64** to C:\Python27\Lib\site-packages
instead of, place cv2.pyd from C:\opencv\build\python\2.7\ **x86** to C:\Python27\Lib\site-packages
I got this error when trying to import MySQLdb.
What worked for me was to uninstall Python and then reinstall it.
I got the error after installing npm (https://www.npmjs.com/get-npm). One thing it did was install Python even though I already had it.
First I copied cv2.pyd from /opencv/build/python/2.7/x86 to C:/Python27/Lib/site-packeges. The error was
"RuntimeError: module compiled against API version 9 but this version of numpy is 7"
Then I installed numpy-1.8.0-win32-superpack-python2.7.exe and OpenCV works fine.
>>> import cv2
>>> print cv2.__version__
2.4.13
Please make sure that you have installed a Python 2.7.12 or below version. Otherwise you will definitely get this error.
Make sure the Oracle client is 64 bit installed if the OS is 64 bit.
Make sure the Microsoft Visual C++ compiler for Python 2.7 is 64 for bit for a 64 bit OS or 32 bit for 32 bit.
Note: If your OS is 64 bit, install all packages of 64 bit or if the OS is 32 bit, install the 32-bit package.
This has worked for me. I have tried different methods, but this was my best solution.
Open a command prompt and type the following;
pip install opencv-python
(Make sure your Internet connection is on.)
After that, try importing it again.
It could also be that your Anaconda version is 32 bit when it should be 64 bit.
If you are using pycharm I go to settings -> python interpretation and click the + button and search for the name on the list of python packages there
An image showing where to go when you want to install something
I found the solution. Maybe you can try to use the cmd window rather than the Anaconda prompt window to start your first Scrapy test.
i want to make this work on freebsd
I am always receiving this error when trying to generate a thumbnail with the easy_thumbnails module:
InvalidImageFormatError: The source file does not appear to be an image
I have tried installing PIL from source by specifying the library
paths in the setup.py file
I have tried installing PILLOW instead.
I tried it both on python27 and python26
I tried installing PIL with easy install instead of pip, both on PILLOW and PIL
I have py-imaging installed and my tests on the PIL library show ok
btw the exact python code works fine on a RHEL box
any other suggestions for things to try here
thank you in advance
That's usually a sign that PIL is not finding the libraries for the image type. You mentioned that you installed from source with the library paths specified. Did you include all the libraries? Do you have the JPEG port installed? Did you try installing PIL from ports. The port defaults to include JPEG, ZLIB, Freetype2, etc.
Recently, I have been studying OpenCV to detect and recognize faces using C++. In order to execute source code demonstration from the OpenCV website I need to run Python to crop image first. Unfortunately, the message error is 'ImportError: No module named Image' when I run the Python script (this script is provided by OpenCV website). I installed "python-2.7.amd64" and downloaded "PIL-1.1.7.win32-py2.7" to install Image library. However, the message error is 'Python version 2.7 required, which was not found in the registry'. And then, I downloaded the script written by Joakim Löw for Secret Labs AB / PythonWare to register registry in my computer. But the message error is "Unable to register. You probably have the another Python installation".
I spent one month to search this issue on the internet but I cannot find the answer. Please support me to resolve my issue.
Thanks,
Tran Dang Bao
You installed the 64-bit version of Python, but the 32-bit version of PIL. Either switch to the 32-bit version of Python, or you need a 64-bit version of PIL (not available that I could find). There is pillow, a PIL-compatible replacement that might work. A 64-bit version is available here:
Pillow-2.1.0.win-amd64-py2.7.exe
The solution is very simple. You don't need to worry about x86 or 64 bit,
all you have to do is import as follows:
from PIL import Image
but make sure Pillow is installed.
Works for me.
Try to put the python(2.7) at your Windows path.
Do the following steps:
Open System Properties (Win+Pause) or My Computer and right-click then Properties
Switch to the Advanced tab
Click Environment Variables
Select PATH in the System variables section
Click Edit
Add python's path to the end of the list (the paths are separated by semicolons).
example C:\Windows;C:\Windows\System32;C:\Python27
I'm using Ubuntu, Django 1.3, Python 2.7.
When I try to upload certain types of image, I get this message:
Upload a valid image. The file you uploaded was either not an image or a corrupted image.
It's happening with PNG and JPG (the formats that I need).
tiff and gif (that I don't and will never care about) are working.
What can I do ?
Install PIL !
$ sudo apt-get install python-imaging
(for Ubuntu or other Debian distrib)
And don't forget about jpeg-lib! Without it PIL willn't understand with what format it can works.
If you get this error and you've PIL installed on Ubuntu check that you've jpeg, freetype, zlib libraries installed.
I suggest you also to use apt/aptitude rather than pip/easy_install.
If you really want to install PIL with pip please notice that the PIL setup will not find your installed libraries (libjpg ...) because Ubuntu installs those libs
here -> /usr/lib/x86_64-linux-gnu for 64bit
or
here -> /usr/lib/x86_32-linux-gnu for 32bit
to fix this you can add this to the setup.py (of course you need to download a copy of PIL from here -> http://www.pythonware.com/products/pil/)
around line 200 (you should see other paths around there)
add_directory(library_dirs, "/usr/lib/x86_64-linux-gnu")
I found that this error can be caused by IntegrityError while saving to db