Модуль OpenCV работает без ошибок в коде Vs, Spyder Но он работает с ошибками в python IDEL И не импортирует библиотеки, когда я открываю Терминал всех этих редакторов Терминал Vscode не импортирует библиотеки Python IDEL не импортирует библиотеки Anaconda Prompt импортирует библиотеки
Итак, моя ошибка В чем проблема с python IDEL и терминалом кода VS? И как я могу это решить?
#VS CODE
import cv2
from os import path
video = cv2.VideoCapture(0)
xml_classifier = path.join(path.dirname(cv2.__file__),
"data", "haarcascade_frontalface_default.xml")
while True:
grabbed, frame = video.read()
frame = cv2.resize(frame, (800, 500))
def detect_faces(frame):
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face_calssifier = cv2.CascadeClassifier(xml_classifier)
rects = face_calssifier.detectMultiScale(gray,
scaleFactor=1.15,
minNeighbors=5,
minSize=(30, 30))
return rects
def draw(frame, rects, title): # , text):
print("=" * 30)
print("i found {} people.".format(len(rects)).title())
print("=" * 30)
for x, y, w, h in rects:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
if title:
cv2.imshow(title, frame)
draw(frame, detect_faces(frame), "Video")
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video.release()
cv2.destroyAllWindows()
### In Vs code terminal ---------------------------------------------------------------------
PS C:\Users\ASUS> & C:/Users/ASUS/Anaconda3/Anaconda/python.exe c:/Users/ASUS/Computer-Vision-Projects/FDVW.py
==============================
I Found 1 People.
==============================
==============================
I Found 1 People.
==============================
==============================
I Found 1 People.
==============================
==============================
I Found 1 People.
==============================
==============================
I Found 1 People.
==============================
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback
PS C:\Users\ASUS> python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
>>> import flask
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'flask'
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>> import os
>>>
# In python Idle
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
>>> import numpy
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import numpy
ModuleNotFoundError: No module named 'numpy'
>>> import flask
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import flask
ModuleNotFoundError: No module named 'flask'
>>> import os
>>>
=== RESTART: C:\Users\ASUS\Computer-Vision-Projects\#01_face_detection.py ===
Traceback (most recent call last):
File "C:\Users\ASUS\Computer-Vision-Projects\#01_face_detection.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
>>>
Но в приглашении Anaconda он работает без ошибок и импортирует библиотеки, а Spyder запускается без ошибок
(base) C:\Windows\system32>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import flask
>>> import numpy
>>> import os
Такая же ошибка в opencv есть в flask, numpy и et c. Путь python в настройках кода VS: "python .pythonPath": "C: \ Users \ ASUS \ Anaconda3 \ Anaconda \ python",
Мои настройки VSCode
{
"editor.fontSize": 22,
"editor.rulers": [80],
"editor.fontWeight": "500",
"debug.console.fontSize": 16,
"terminal.integrated.fontSize": 16,
"terminal.integrated.fontWeight": "100",
// "files.autoSaveDelay": 500,
"files.autoSave": "onFocusChange",
"workbench.iconTheme": "material-icon-theme",
"terminal.integrated.shell.linux": "/usr/bin/zsh",
// "terminal.integrated.inheritEnv": false,
//? linux
// "python.pythonPath": "/usr/bin/python3.8",
//? py36
"python.pythonPath": "C:\\Users\\ASUS\\Anaconda3\\Anaconda",
"python.formatting.provider": "autopep8",
"[python]": {
"editor.defaultFormatter": "ms-python.python"
},
"workbench.colorCustomizations": {
"terminal.foreground": "#f0a212",
"terminal.background": "#161C28",
// "terminal.background": "#232F34",
"tab.activeBorder": "#02e039",
// "activityBar.activeBackground":"#1684b3a9",
"activityBar.activeBorder": "#02e039",
// "list.inactiveSelectionBackground": "#86a9fb",
"statusBar.background": "#333",
"statusBar.foreground": "#fff",
"statusBar.noFolderBackground": "#333",
"statusBar.noFolderForeground": "#fff"
},
"gotoNextPreviousMember.symbolKinds": ["function"],
"editor.formatOnSave": true,
"editor.showFoldingControls": "mouseover",
"python.jediEnabled": false,
// "workbench.statusBar.feedback.visible": false,
"editor.minimap.enabled": false,
"workbench.settings.editor": "json",
//!READ THIS ARTICLE TO CUSTOMIZE THE TERMINAL
//? https://pascalnaber.wordpress.com/2019/10/05/have-a-great-looking-terminal-and-a-more-effective-shell-with-oh-my-zsh-on-wsl-2-using-windows/
"terminal.integrated.fontFamily": "Source Code Pro Semibold",
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.cursorBlinking": true,
"workbench.startupEditor": "newUntitledFile",
"git.autofetch": true,
"workbench.list.openMode": "singleClick",
"zenMode.hideLineNumbers": false,
"zenMode.hideTabs": false,
"workbench.activityBar.visible": true,
"git.enableSmartCommit": true,
"window.zoomLevel": -1,
"editor.defaultFormatter": "ms-python.python",
// "terminal.integrated.rendererType": "dom",
"sync.autoUpload": true,
"sync.forceUpload": true,
"sync.gist": "13d7fc3f673defc7dc0cba7f7d3dd8a5",
"workbench.colorTheme": "Newton (rainglow)",
"kite.showWelcomeNotificationOnStartup": false,
"extensions.ignoreRecommendations": false,
"python.dataScience.sendSelectionToInteractiveWindow": true,
"vsicons.dontShowNewVersionMessage": true,
"editor.columnSelection": false,
"dart.debugExternalLibraries": true,
"dart.debugSdkLibraries": false,
"dart.previewHotReloadOnSaveWatcher": true,
"editor.multiCursorModifier": "alt",
"editor.formatOnPaste": true,
"[dart]": {
"editor.tabSize": 4,
"editor.insertSpaces": false,
"editor.formatOnSave": true
},
"python.linting.enabled": true,
"editor.tabSize": 4,
//!############################################################
"window.titleBarStyle": "custom",
"window.enableMenuBarMnemonics": false,
"window.customMenuBarAltFocus": false,
//!############################################################
}