How To Install Opencv For Python 3.6 (64-bit) In Windows
Solution 1:
I thought had the same problem after I upgraded to python 3.6.2 64bit architecture. But it turned out that I was installing by..
pip install cv2
... on python 3.6.2 x64 instead of..
pip install opencv-python
Solution 2:
Here are the steps I followed to get OpenCV 4.2 to run on Python 3.7.6 (x86-64) in Windows 10:
Install prerequisite software on Windows:
- Python 3.7.6 (x86-64)
- OpenCV 4.2.0 (or later) and extract it to
C:\
- Visual Studio Community 2017
- CMake for Windows
Install prerequisite packages on Python:
- numpy
- matplotlib
Build OpenCV for x64:
- Open CMake (cmake-gui), specify where OpenCV source code is and where the build directory should be and mark those 2 checkboxes before pressing the Configure button:
- The next window lets you select the compiler and desired architecture:
- After the initial project configuration is over, CMake will display several build flags to let you enable/disable support for certain libraries or features. Make sure that PYTHON3 lists the correct paths to your python (x64) and adjust it if necessary:
- Open the ENABLE group and uncheck
ENABLE_SOLUTIONS_FOLDER
:
(Optional) Enable the build of opencv_contrib module: this is an external module that doesn't ship with OpenCV source code. To allow OpenCV to build it, you need to clone this GitHub repo somewhere in your computer. Then, simply find and initialize the
OPENCV_EXTRA_MODULES_PATH
with the location of<opencv_contrib>/modules
. For example, in my computer the correct path would be something like:C:\opencv_contrib\modules
After adjusting all the flags that you want (or need), simply click the Generate button to create the VS project that you will use to build OpenCV. When it finishes, the button Open Project will be enabled. Click on it to open Visual Studio:
- On Visual Studio, make sure to select the Release configuration:
- Build the ALL_BUILD recipe (right click on it, then select Build).
- Once that build is done, you need to build the INSTALL recipe (right click on it, then select Build) to install all the artifacts in their place. And that's it! Open Python and
import cv2
.
If you encounter errors while building the INSTALL script, you might have to close Visual Studio and open it with Administrator privileges so that it can install the cv2
package for python.
Post a Comment for "How To Install Opencv For Python 3.6 (64-bit) In Windows"