简体   繁体   English

Python 3 Opencv 设置问题:“在 __init__.py 中找不到引用‘VideoCapture’” on Pycharm IDE

[英]Python 3 Opencv set up problem: "cannot find reference 'VideoCapture' in __init__.py" on Pycharm IDE

I am trying to install OpenCv and run some code on PyCharm on Mac.我正在尝试安装 OpenCv 并在 Mac 上的 PyCharm 上运行一些代码。

I have installed the opencv package as well as numpy but when I run the code this error shows up on Pycharm IDE: "cannot find reference 'VideoCapture' in __init__.py"我已经安装了 opencv package 以及 numpy,但是当我运行代码时,此错误显示在 Pycharm IDE 上: "cannot find reference 'VideoCapture' in __init__.py"

In fact, every time I write example_variable = cv2.其实每次写example_variable = cv2. , PyCharm is not giving me any option to autocomplete with a function attached to cv2. , PyCharm 没有给我任何选项来自动完成附加到 cv2 的 function。 Why is this happening?为什么会这样?

Here's the code I am trying to run.这是我要运行的代码。 I tried also running other codes but the same error displays:我也尝试运行其他代码,但显示相同的错误:

import cv2
import numpy as np

cap = cv2.VideoCapture()

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    cv2.imshow('frame',gray)

    if cv2.waitKey(1) & OxFF == ord('q'):
        break

cap.release
cv2.destroyAllWindows()

Any tips on how to run this code smoothly?有关如何顺利运行此代码的任何提示? The end goal is to have my front webcam capture live video and react to it.最终目标是让我的前置网络摄像头捕捉实时视频并对其做出反应。

Try one of this solutions:尝试以下解决方案之一:

  1. Right-click on source Directory右键单击源目录
  2. Mark Directory as -> source root将目录标记为 -> 源根目录
  3. File --> Invalidate Caches / Restart... -> Invalidate and Restart文件 --> 使缓存无效/重新启动... -> 使缓存无效并重新启动

OR:或者:

  1. In your IDE, go to settings -> preferences -> django在您的 IDE 中,转到设置 -> 首选项 -> django
  2. Ensure your Root directory, your settings.py and your manage.py are in the right place if you are in Django.如果您在 Django 中,请确保您的 Root 目录、settings.py 和 manage.py 位于正确的位置。

After all that, you can also delete the .idea folder in your root directory and restart the IDE.毕竟,您还可以删除根目录中的 .idea 文件夹并重新启动 IDE。

而不是import cv2使用from cv2 import cv2

I agree with "from cv2 import cv2"我同意“从 cv2 导入 cv2”

there have an another way to solve problems:还有另一种解决问题的方法:

** Do Not Use Pip Install ** ** 不要使用 Pip 安装 **

I try to use download opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl file and then manual double click to install我尝试使用下载 opencv_python-4.5.5.62-cp36-abi3-win_amd64.whl 文件然后手动双击安装

wait a minute, Pycharm IDE successfully Show code completion.稍等一下,Pycharm IDE 成功显示代码完成。


by the way,can your code run?顺便问一下,你的代码可以运行吗?

if code can run, above will help you a bit.如果代码可以运行,上面会帮助你一点。

and your path(project python) should be Englisgh ;并且您的路径(项目 python)应该是 Englisgh ; not be Chinese or other language.不是中文或其他语言。

This worked for这适用于

  1. Before I was using python from Anaconda, instead在我使用 Anaconda 中的 python 之前,
  2. Choose the default python interpreter选择默认的 python 解释器

pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62 pip 安装 --force-reinstall --no-cache -U opencv-python==4.5.5.62

  1. use this command line to avoid the reference issue.使用此命令行可避免引用问题。

只需输入 from cv2 import cv2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 安装 opencv 后,如何解决 python 中的“Cannot find reference 'imread' in '__init__.py”错误? - How to resolve this error of "Cannot find reference 'imread' in '__init__.py" in python after installing opencv? 在“__init__.py”中找不到参考“TextVectorization” - Cannot find reference 'TextVectorization' in '__init__.py' 在 __init__.py 中找不到引用“xxx” - Cannot find reference 'xxx' in __init__.py PyCharm 在 __init__.py 中找不到任何 OpenCV function 的参考 - PyCharm can´t find reference of any OpenCV function in __init__.py Tensorflow 可以在 Pycharm 中使用,但在 __init__.py 中找不到引用 `xxx` - Tensorflow can be used in Pycharm, but cannot find reference `xxx` in __init__.py 在 __init__.py [暂停] 中找不到引用“ref_name” - Cannot find reference 'ref_name' in __init__.py [on hold] 为什么 pygame 在“__init__.py”中找不到引用“...”? - Why pygame cannot find reference '…' in '__init__.py'? 在“ __init __。py” Google自定义搜索API中找不到引用“发现” - Cannot find reference 'discovery' in '__init__.py' Google custom search API Python OpenCV 的基本命令“Cannot find reference in '__init__'.py - Python OpenCV's basic commands "Cannot find reference in '__init__'.py 带有__init__.py的Python ModuleNotFoundError - Python ModuleNotFoundError with __init__.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM