ModuleNotFoundError: No module named 'cv2' How can I install packages in python folders? rather than in anaconda - opencv

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...).

Related

Raspberry Pi Open CV Install

I installed opencv-python and opencv-python-contrib
after i installed them I realized I wasn't supposed to
How do I uninstall it
Also, which one should I keep, to do facial recongnition with raspberry pi
Import cv2 didn't work when I tried to run a python file, I don't know why it is happening!
If you are using armbian or raspbian, you can uninstall packages with apt:
apt uninstall opencv-python opencv-python-contrib
I suggest that if you want to completely uninstall and remove configuration files use purge:
apt purge opencv-python opencv-python-contrib
and aftter that, you can uninstall packages that came with opencv:
apt autoremove --purge
If you need Extra modules: just keep opencv-python-contrib
Extra modules https://docs.opencv.org/4.x/index.html
pypi.org https://pypi.org/project/opencv-contrib-python/
Installation and Usage
If you have previous/other manually installed (= not installed via pip) version of OpenCV installed (e.g. cv2 module in the root of Python's site-packages), remove it before installation to avoid conflicts.
Make sure that your pip version is up-to-date (19.3 is the minimum supported version): pip install --upgrade pip. Check version with pip -V. For example Linux distributions ship usually with very old pip versions which cause a lot of unexpected problems especially with the manylinux format.
Select the correct package for your environment:
There are four different packages (see options 1, 2, 3 and 4 below) and you should SELECT ONLY ONE OF THEM. Do not install multiple different packages in the same environment. There is no plugin architecture: all the packages use the same namespace (cv2). If you installed multiple different packages in the same environment, uninstall them all with pip uninstall and reinstall only one package.
a. Packages for standard desktop environments (Windows, macOS, almost any GNU/Linux distribution)
Option 1 - Main modules package: pip install opencv-python
Option 2 - Full package (contains both main modules and contrib/extra modules): pip install opencv-contrib-python (check contrib/extra modules listing from OpenCV documentation)
b. Packages for server (headless) environments (such as Docker, cloud environments etc.), no GUI library dependencies
These packages are smaller than the two other packages above because they do not contain any GUI functionality (not compiled with Qt / other GUI components). This means that the packages avoid a heavy dependency chain to X11 libraries and you will have for example smaller Docker images as a result. You should always use these packages if you do not use cv2.imshow et al. or you are using some other package (such as PyQt) than OpenCV to create your GUI.
Option 3 - Headless main modules package: pip install opencv-python-headless
Option 4 - Headless full package (contains both main modules and contrib/extra modules): pip install opencv-contrib-python-headless (check contrib/extra modules listing from OpenCV documentation)

Getting error in Jupyter Notebook when importing opencv after installation: libGL.so.1: cannot open shared object file: No such file or directory

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/

Installing OpenCV into PyCharm

Idk if this is a stackoverflow-appropriate post so forgive if the question is misplaced. I'm trying to install OpenCV into my Pycharm IDE through the conda virtual environment. I typed conda install -c conda-forge opencv inside the PyCharm terminal and it has been doing this for 11 hours and God knows how many more to go.
Pycharm did this with PyTorch as well. Am I doing something wrong or is this normal?
While you can install packages directly in PyCharm by going to file->settings select Project Interpreter and click on the '+' icon on the top right (see image)
I would recommend creating a requirements.txt file in the root of your project, and write down all your required packages. When a package is missing, PyCharm will automatically suggest to install the package for you.
e.g. for installing opencv you can add the following to you requirements.txt
opencv-python
Or even specify the version that your project needs
opencv-python==4.1.2
edit: the advantage of using a requirement.txt is that you can more easily port the project to another machine, and re-install the packages if needed.

install package using pip (version confused)

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!

unable open C:\Program Files (x86)\Python36-32\share\kivy-examples\demo\showcase\main.py in windows10

I installed kivy using pip's latest wheels but I can't load C:\Program Files (x86)\Python36-32\share\kivy-examples\demo\showcase\main.py in windows10. Can anyone help me?
When you install the kivy examples on Windows 10 using the following:
python -m pip install kivy_examples
or
python -m pip install Kivy_examples-1.10.1.dev0-py2.py3-none-any.whl
If your user is named "usr", the kivy examples are installed in the following location:
C:\Users\usr\AppData\Local\Programs\Python\Python36\share\kivy-examples
To run the showcase example, do the following:
python C:\Users\usr\AppData\Local\Programs\Python\Python36\share\kivy-examples\demo\showcase\main.py

Resources