简体   繁体   中英

Import Error: No module named cv2 (Python, Atom IDE)

I'm having trouble with importing the cv2 module ( import cv2 ) in Atom. I came across this link , but already did pip install opencv-python . Is there any other package on Atom I can download to make it work?

This is the error I get:

Traceback (most recent call last):
  File "/Users/bubbles/Desktop/Face dataset 2/eigenface.py", line 5, in <module>
    import cv2
ImportError: No module named cv2
[Finished in 1.208s]

(Note: The program runs on Terminal, but I can't seem to execute it on Atom)

Seems like this either did not get installed properly or you are not selecting the right environment. Things I would do:

  • Check if you are using the correct env and if the library is installed in that env.
  • Make a new virtual env and install it there. Don't think you'd need to do this but if you don't have an isolated env, it may cause issues like this.
  • Try anaconda distribution for python

Finally, I don't think you are using the right environment where it got installed. Alternatively, uninstall and install it again. Feel free to ask any follow-up questions.

You should also check if the python version is compatible with the opencv version.

The problem is that your compiler probably points out to the python version 2.7 or any other which has usr/local/lib/python2.7/dist-packages folder empty. In order to confirm that, paste this line on the beginning of your.py file: #!/usr/bin/python3 . If cv2 was imported successfully by using this workaround, proceed with the following steps.

Now, how to switch the default version of python to 3.8 or higher?

  1. List all the installed versions of Python 3: ls /usr/bin/python3*

  2. Add Python 3.8 to the alternatives list and change its priority: sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1

  3. Change the default version of Python by using following command:

    sudo update-alternatives --config python

Type the number of the version you wish to set as default and confirm with enter.

  1. Confirm that the change was successfully introduced by: python -V

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM