(已解决-cv2包正常导入,但调不熬内置函数)PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘(以解决)

 cv2包已经可以正常引用,但是,部分函数调用不到,以imread举例

import cv2
import requests
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as Wait

driver = webdriver.Chrome()  # 创建Chrome对象
# driver.get('https://www.baidu.com')  # 访问百度.
driver.get("https://www.douban.com/")

driver.implicitly_wait(20)

driver.switch_to.frame(driver.find_element(By.XPATH,"//*[@id='anony-reg-new']/div/div[1]/iframe"))
driver.find_element(By.XPATH, "/html/body/div[1]/div[1]/ul[1]/li[2]").click()

driver.find_element(By.XPATH, "//*[@id='username']").send_keys("17600299304")
driver.find_element(By.XPATH, "//*[@id='password']").send_keys("17600299304")
driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[1]/div[5]").click()
driver.switch_to.frame(driver.find_element(By.XPATH,'//*[@id="tcaptcha_iframe"]'))
# Big_img=driver.find_element(By.XPATH,'//*[@id="slideBg"]')
Big_img=driver.find_element(By.XPATH,'//*[@id="cdn1"]')

# //*[@id="cdn1"]
# Sim_img=driver.find_element(By.XPATH,'//*[@id="slideBlock"]')
Sim_img=driver.find_element(By.XPATH,'//*[@id="cdn2"]')
Big_url=Big_img.get_attribute('src')
Sim_url=Sim_img.get_attribute('src')
print(Big_url)
print(Sim_url)

# 下载滑块和花瓣图到本地

with open('11/Big_images.jpg', 'wb') as f:
    f.write(requests.get(Big_url).content)
    f.close()
with open('11/Sim_images.jpg', 'wb') as f:
    f.write(requests.get(Sim_url).content)
    f.close()

#人工智能匹配滑块验证距离

cv2.imread()

(已解决-cv2包正常导入,但调不熬内置函数)PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘(以解决)_第1张图片

https://blog.csdn.net/m0_60258123/article/details/121416424https://blog.csdn.net/m0_60258123/article/details/121416424文章中通过修改opencv的版本,完美解决了这个问题,没有了warning,并且代码提示功能也能正常运行了。pip install -i https://pypi.douban.com/simple opencv-python==4.5.3.56,

但我的报如下问题

C:\Users\euweb>pip install -i https://pypi.douban.com/simple opencv-python==4.5.3.56
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.douban.com/simple
Collecting opencv-python==4.5.3.56
  Using cached https://pypi.doubanio.com/packages/01/9b/be08992293fb21faf35ab98e06924d7407fcfca89d89c5de65442631556a/opencv-python-4.5.3.56.tar.gz (89.2 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Program Files\Python310\python.exe' 'C:\Users\euweb\AppData\Local\Temp\pip-standalone-pip-xzw6is2a\__env_pip__.zip\pip' install --ignore-installed --no-user --prefix 'C:\Users\euweb\AppData\Local\Temp\pip-build-env-gtx9nthp\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.douban.com/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_machine != '"'"'aarch64'"'"' a

https://blog.csdn.net/baidu88vip/article/details/89313548https://blog.csdn.net/baidu88vip/article/details/89313548文章中通过pip install opencv-contrib-python命令来解决问题,但是我操作后出现如下问题

C:\Users\euweb>pip install opencv-contrib-python
Defaulting to user installation because normal site-packages is not writeable
Collecting opencv-contrib-python
  Downloading opencv_contrib_python-4.6.0.66-cp36-abi3-win_amd64.whl (42.5 MB)
     |████████████████████████████████| 42.5 MB 352 kB/s
Collecting numpy>=1.17.3
  Using cached numpy-1.22.4-cp310-cp310-win_amd64.whl (14.7 MB)
Installing collected packages: numpy, opencv-contrib-python
  WARNING: The script f2py.exe is installed in 'C:\Users\euweb\AppData\Roaming\Python\Python310\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.22.4 opencv-contrib-python-4.6.0.66
WARNING: You are using pip version 21.2.4; however, version 22.1.2 is available.
You should consider upgrading via the 'C:\Program Files\Python310\python.exe -m pip install --upgrade pip' command.

把引用的“cv2“包中的cv2.pyd文件,挪到上一级目录

(已解决-cv2包正常导入,但调不熬内置函数)PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘(以解决)_第2张图片

 (已解决-cv2包正常导入,但调不熬内置函数)PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘(以解决)_第3张图片

你可能感兴趣的:(python,pycharm,python,ide)