The solution to the problem of installing opencv and pycharm importing cv2 in win10 +python3.6 environment

 1. Install opencv

  The blog I used for reference has been written very clearly ------- https://blog.csdn.net/u011321546/article/details/79499598 , here I just record my own installation process

  It stands to reason that there should be two ways to install opencv here, one way is to install with python's pip, and the other way is to install it directly in Pycharm, but after trying it, I found that the second method was wrong, as shown in the figure below.

  

  The reason for the error is "try to run this command from the system terminal", so we can only use the first method to pip install.

  Before installing opencv, install pip first. The installation method of pip is as follows:

  Enter the Scripts path in the Python installation directory and execute easy_install-3.6.exe pip             (because my python version is 3.6). After executing this command, pip is installed successfully. The functions of pip are as follows:

  

 

  After installing pip, then install opencv (other module installations are also similar to the following method):

  Enter the Scripts path in the Python installation directory and execute   pip install opencv-python 

  

  这里要查看安装的opencv的版本话需要在,需要在命令行终端(或python自带的IDLE中)运行如下代码即可查看:

  import cv2

  cv2.__version__

  The effect is as follows, you can know that my opencv version is 3.4.0

  

 

 

Second, the solution to the problem of pycharm importing cv2

  After pip installs opencv, but importing cv2 in pycharm will still report an error, why is this? I also Baidu for a while to find a solution, here is the reference blog: https://blog.csdn.net/Eclipsesy/article/details/77686807 This blog solved my problem very well, but the method in the blog is the last It feels a bit redundant at all, and only the first step is needed to solve the problem.

  Solution:

  To determine whether the environment variable in pycharm contains python's environment lib, the viewing method is shown in the following figure:

  

  Click Show All, click the red circle to see the search path of pycahrm, and finally see if the path of the yellow circle is added. Note: Pycahrm can import cv2 correctly only if the path in the yellow circle is added (the folder site-packages must be included).

 

  

      

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325267574&siteId=291194637