The command
import cv2
on Watson Studio results in the error
ImportError Traceback (most recent call last)<ipython-input-1-72fbbcfe2587> in <module>()----> 1 import cv2
ImportError: No module named 'cv2'
I'm not sure if I need to install opencv upfront and how to do this in a cloud environment like Watson Studio?
cv2 is part of opencv-python package.
Please install the pypi hosted libararies using !pip magic in jupyter notebook.
!pip install opencv-python
Then run the import cv2.
See this shared notebook
https://dataplatform.ibm.com/analytics/notebooks/v2/a0e50c53-ea28-4b78-800f-35cae2211389/view?access_token=b129fa46626e1bf317de18c9241af375d9a9ac8e11561e3735569050fe0b8839
Also see this documentation for installing third party libraries.
https://datascience.ibm.com/docs/content/analyze-data/importing-libraries.html
Related
I have installed python3 in my ubuntu 20.04LTS operating system. I have also installed the Jupyter notebook directly from the snap store. Now I am trying to install OpenCV from jupyter notebook using: pip install OpenCV-python.
I have also tried: !pip install OpenCV-python
In both the case it says requirement already satisfied. Below is the screenshot:
Whenever I am trying: import cv2.
It gives error:libGL.so.1: cannot open shared object file: No such file or directory.
Though I have installed OpenCV through the terminal in python3 and it successfully gets imported in python3 terminal. But not able to import in Jupyter notebook.
Please suggest, how can I resolve this issue and import OpenCV to Jupyter Notebook.
Any link where I can learn and understand how these libraries interact with the operating system when installed through python and Jupyter notebooks will be helpful.
Thanking you!
This is happening due to using pre-built CPUs. Install package as headless one.
I had similar issue that got resolved by using below command
pip install opencv-python--headless
reference https://pypi.org/project/opencv-python-headless/
I have previously installed python 3.7, anaconda3 and jupyter notebook.
Then I tried to install opencv library using the following command.
pip install opencv-python
and it said,
Requirement already satisfied: opencv-python in c:\programdata\anaconda3\lib\site-packages (4.1.1.26)
When I tried to import open-cv library from IDLE it gives the following error.
ModuleNotFoundError: No module named 'cv2'.
But when I run it from the jupyter notebook it works.
The reason for this as I see is that the packages are installed in the anaconda3 folders but not in the python folders.
How can I install packages in python folders? As I need to run this from the IDLE.
I'm using python 3.7.1 on windows 10.
Thank you.
what IDLE are u using for program in python? If you are using Python IDLE, usually when you import packages, are installed in C:\Users\Your_Username\AppData\Local\Programs\Python\Python37-32\Lib
If you want to install a package in other folder, try to use this
pip install --target=C:\path\to\folder\ opencv-python
If you have another IDLE, put me in the comments what is it (PyCharm, VSCode...).
I am trying to import the opencv library into sikuliX which uses Jython interpreter.
I have added the path where cv2 module is installed to sys.path.append to tell Jython to look for cv2 folder in the path supplied.
import sys
sys.path.append("/Users/ongyichong/anaconda3/lib/python3.7/site-
packages/")
import cv2
I installed opencv using pip install opencv-contrib-lib and the path where cv2 is installed in the path "/Users/ongyichong/anaconda3/lib/python3.7/site-packages/".
This is what my cv2 folder looks like.
The error arises because my init.py file contains a ".cv2 import *". I am not sure how i should go about solving this problem. Is there another way i can import python modules into SikuliX's Jython interpreter ?
Python (C-Python) modules can only be used in SikuliX (Jython interpreter) when they are completely written in Python language and do not contain any C-based stuff or even reference native libraries.
BTW: especially since SikuliX 1.1.4 the complete OpenCV 3 API is available at the Java level, which is also accessible from the Jython scripting level.
I think since I'm new to python, I installed packages in multiple subversion. like python 2.7.15 or python 2.7.14.
If I import certain package (e.g., hdf5storage) using terminal (python 2.7.15), I can >> import hdf5storage
but if I import the package using jupyter notebook (python 2.7.14), i cannot. >> import hdf5storage
no module called hdf5storage.
I didn't install this different version on purpose, it just happened.
I used pip2 to install packages. Can anyone explain how to solve this issue, for a beginner? How do I use virtualenv or edit PATH, it's very confusing for me. Any answer would be appreciated!
I Installed opencv and cv2 in anaconda and created a tensorflow environment for imageprocessing.
tensorflow is present in
c:/Users/mayank singh/local/conda/conda/envs/tfdeeplearning/lib/site-packages
And cv2 is prensent in
c:/Programdata/Anaconda3/lib/site-packages
cv2 is working independently in jupyter notebook but shows error "module not found" after activating tensorflow