I am having some trouble downloading and importing the OpenCV library. In my Terminal, I executed
pip3 install opencv-python
and I got the following response:
Requirement already satisfied: opencv-python in ./opt/anaconda3/lib/python3.8/site-packages (4.4.0.42)
Requirement already satisfied: numpy>=1.17.3 in ./opt/anaconda3/lib/python3.8/site-packages (from opencv-python) (1.18.5)
I then tried to start a python3 session in my Terminal, and I could execute import cv2 successfully without any errors. However, when I tried to execute import cv2 in Visual Studio Code, I get the following error:
Traceback (most recent call last):
File "motiondetector.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I also get the same error when I am running my code on IDLE.
Does anyone know why this errror occurs? Any help would be much appreciated. Thanks in advance!
Just found the answer - I had to install the OpenCV module in the IDE as well! Thank you to everyone who helped! :)
Related
I am making a JARVIS AI for my UBUNTU 20.4.3 . I'd installed pyttsx3 but still I am getting an error. Please help in this:
macos#UBUNTU20:~/Python$ python -u "/home/macos/Python/jarvis.py"
Traceback (most recent call last):
File "/home/macos/Python/jarvis.py", line 1, in <module>
import pyttsx3
ImportError: No module named pyttsx3
macos#UBUNTU20:~/Python$ pip install pyttsx3
Requirement already satisfied: pyttsx3 in /home/macos/.local/lib/python3.8/site-packages (2.90)
On many Mac/Linux computers (in this case Ubuntu), there is a Python 2 distribution installed. If python --version prints something like
Python 2.7.9
You can solve the confusion by running python3 instead of python:
python3 -u "/home/macos/Python/jarvis.py"
UPDATE: Thank you to everyone who answered and commented. I understand now that I have 2 versions of python installed. My program was running from "Miniconda3/python.exe ". While bs4 was installed in "c:\python38\lib\site-packages". I understand this to be the cause of the problem. I removed Minicoda3 but VS code still tries to use it when I run a program. How can I fix this?
When I run the following code:
>>> from bs4 import BeautifulSoup
Error:
I get the error: "No module named 'bs4'.
After I install bs4, It says "Requirement already satisfied" yet I get the same error.
Im not sure what I'm doing wrong, please help. Error messages below.
PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>
You are using miniconda, which might not be on your PATH correctly such that pip is actually part of a separate Python installation.
You could use conda install pip, or C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
Okay so my problems are fixed an my program is running. Like I said in the update the first problem was due to having 2 versions of python installed. After I removed the unwanted version it was still set as the python interpreter path. I was trying to fix this by going into VS code settings but was having no luck. Fortunately I finally noticed there was a button on bottom left of the screen that allowed me to change the path easily. Thanks again to those who commented and answered.
I am very new to Python and have reviewed multiple questions here on problems getting packages/modules to import but can't seem to work out what I'm doing wrong. I'm simply trying to import packages and use them in the Spyder console, I'm used to working in R Studio so that's kind of my point of reference.
I run the below code and receive the following messages.
pip install Pillow
Requirement already satisfied: Pillow in c:\users\name\anaconda3\lib\site-packages (7.0.0)
Note: you may need to restart the kernel to use updated packages.
import Pillow
Traceback (most recent call last):
File "<ipython-input-7-f4cbff62aba7>", line 1, in <module>
import Pillow
ModuleNotFoundError: No module named 'Pillow'
I also seem to be getting different results when I run pip install from the console vs from the text editor portion. When I run it from the console, I get the above result about it already being installed. When I run it from the text editor portion, I get the following.
runcell(0, 'C:/Users/name/.spyder-py3/temp.py')
File "C:\Users\name\.spyder-py3\temp.py", line 1
pip install Pillow
^
SyntaxError: invalid syntax
I'm trying to use opencv-python. I imported with pip but it throws ModuleNotFound.
Joshua-Tews-MacBook-Pro:~ nathan$ pip install opencv-python
Requirement already satisfied: opencv-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (4.0.0.21)
Requirement already satisfied: numpy>=1.14.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from opencv-python) (1.16.2)
I import with this:
import cv2
I get this error:
Traceback (most recent call last):
File "/Users/nathan/Library/Mobile Documents/com~apple~CloudDocs/CEP/Y4/Capstone Project (Security Cameras System)/cep-ml-capstone/VideoProcessor.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I've look at the answers on this stackoverflow thread, none seem to help: Cannot import cv2 in python in OSX
Others have solutions I completely didn't recognise pertaining to other OS so I skipped those.
Okay I apparently I just had to run the script with Python 3.7 and it worked. I neglected to mention I was using Textmate.
To run scripts in Python 3.7 using Textmate, go to Preferences > Variables. If there isn't a variable named TM_PYTHON, create one then paste this in for the value: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. Else, just change the value. Be sure to check the box next to the variable.
I'm trying to read a .xlxs file in Python using xlrd, but I keep getting the error Unable to import xlrd.
When I try to re-install xlrd using:
pip install xlrd
I keep getting the message
Requirement already satisfied: xlrd in ./anaconda3/lib/python3.6/site-packages (1.1.0)
And my error message after running my code is
Traceback (most recent call last):
File "/Users/YoungFreeesh/Venture Capital Internship/.../.../Read-csv.py", line 2, in <module>
import xlrd # import the xlrd module
ImportError: No module named xlrd
Also, not sure if this is relevant but I'm using Visual Studio & Python 3.6.5
I'm not sure why I can't import xlrd since I already have it downloaded.
I ran into a similar issue. Make sure you're pip installing the right version (3.x or 2.x). If you're using Python 3, pip3 install xlrd will make sure it is installed and accessible when running Python3 code.