添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams Full Stop, you're trying to do something impossible. Python 2.7 is the ONLY supported python version for cv 2.x series. Read the section: "Supported Python versions: here: pypi.org/project/opencv-python Three workarounds. 1: Just use python2.7 and regular pip, so you can use cv2. 2: Install cv2 from source code so it autodetects your system and from source does the right thing. Finally 3: pitch in and jump on the openCV github and help them make CV2 binary packages in the repos for python3. Eric Leschinski Oct 16, 2018 at 14:49 Of course you may install opencv on python3, this issue is due to missing operating system packages (opencv dependencies, such as gcc) search on google how to install them base on your operating system. I recommend you to use some linux distros, i prefer (and always recommend) Centos-7 it works perfectly. gist.github.com/alundiak/4c0de8d657daa872f31e1df5f9056df8 Jcc.Sanabria Nov 1, 2018 at 15:18

Your screenshot shows you doing a pip install from the python terminal which is wrong. Do that outside the python terminal. Also the package I believe you want is:

pip install opencv-python

Since you're running on Windows, I might look at the official install manual: https://breakthrough.github.io/Installing-OpenCV

opencv2 is ONLY compatible with Python3 if you do so by compiling the source code. See the section under opencv supported python versions: https://pypi.org/project/opencv-python

Better make it pip3 install opencv-python. Sometimes multiple versions of python is available on a system and the default usually is python 2.7. – zindarod Oct 6, 2017 at 17:19 @deadcode: this is really strange... openCV is imported via import cv2 since years now, probably since version 2.0 was introduced in 2009. Maybe you are living up to your name, using the "dead" openCV 1.0? Which python and openCV versions are you using? (check python --version in shell and for cv it usually is print(cv2.__version__) so maybe try opencv.__version__) – Honeybear Feb 21, 2018 at 10:52 I am dead and also a newbie. I can import cv2 from python in terminal which uses 2.7 by default, and cv2 version is 2.4.9.1. But when I open python3, I can only import opencv and that opencv has no attribute version. Maybe now I realise the point of virtualenvs – deadcode Feb 21, 2018 at 11:20

There is a problem with pylint, which I do not completely understood yet.

You can just import OpenCV with: from cv2 import cv2

Please check your python version. Mine is 3.7.3 on a Mac macOS Catalina Version 10.15.7. If you are using Jupyter notebook, pip3 install opencv-python is enough. In your notebook menu click on Kernel and hit restart. Please see the image I included. Kernel>Restart Then run your code again. In my case that solved the problem.

First check your python version, for example 3.10 then you can run this command to check opencv status

python3.10 -m pip show opencv-python

If not installed then install like this,

python3.10 -m pip install opencv-python 

Make sure your IDE is using the correct version of Python

For example, In VSCode, you can press CTRL + Shift + P or (⌘ + Shift + P on Mac) to open the command palette.

Then type "Python select interpreter" in the field and select correct version of python.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.