Symbol not found when importing cv2 - python

I am attempting to import cv2 using python. When I use the import cv2 function in jupyter notebook I get a string of code indicating that the symbol is not found and therefore cv2 cannot be imported. enter image description here
I have tried updating opencv code using various code in my terminal including pip install opencv-python in both my terminal and my jupyter environment. Each time it said that the opencv is installed and that both environments are running on anaconda3 as expected.

Either upgrade your OS-X or install an older version of OpenCV (and python)

Related

How to get librosa.display and matplotlib working in jupyter notebook with anaconda 3.6

I'm trying to get Librosa working with python.
Originally I had Python 2.7 installed, I wasn't able to get Librosa working with Python 2.7 so I installed Anaconda (which I've never used before) so that I could have a separate environment (to allow my old programs written in 2.7 to continue to work). I'm trying to use Jupyter notebook which I've also never used before and I finally managed to import Librosa after creating an Anaconda environment with Python 3.6, however I'm not able to import librosa.display
When I googled "importing Librosa.display" apparently I need to install matplotlib first, however importing matplotlib is failing and I'm not sure why. I think it might be failing due to importing PIL /pillow? however I've never specifically used that module before or had to install it separately when using matplotlib so I'm not sure why it's needed.
I tried reinstalling pillow using PIP install in the anaconda python3.6 environment that I created but it didn't work so now stuck and just wondering if anyone can help me?
for the import code as follows
import matplotlib
import librosa
import matplotlib.pyplot as plt
import librosa.display
The program gets stuck on "import matplotlib.pyplot as plt" and the error message I currently have is as follows (prior to reinstalling pillow it didn't work but the message was different):
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\PIL\Image.py:130: RuntimeWarning: The _imaging extension was built for another version of Pillow or PIL:
Core version: 8.2.0
Pillow version: 8.1.2
warnings.warn(str(v), RuntimeWarning)
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\matplotlib\mathtext.py in <module>()
25
26 import numpy as np
---> 27 from PIL import Image
28 from pyparsing import (
29 Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,
C:\Users\sh\.conda\envs\signalprocess1\lib\site-packages\PIL\Image.py in <module>()
111 if __version__ != getattr(core, "PILLOW_VERSION", None):
112 raise ImportError(
--> 113 "The _imaging extension was built for another version of Pillow or PIL:\n"
114 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
115 f"Pillow version: {__version__}"
ImportError: The _imaging extension was built for another version of Pillow or PIL:
Core version: 8.2.0
Pillow version: 8.1.2
Any help would be great. I don't need to use Jupyter I'm perfectly happy using IDLE if IDLE will work with Librosa and matplotlib through Python 3.6. All I want to do is get Librosa and Matplotlib working so I can analyse signals! I guess if I spend another couple of days on it I'll work it out eventually but it's very annoying spending all this time just trying to get the packages working before I even get to the signal analysis.
thanks!! :)
I'm not sure what I was doing wrong.....
however in the end I got librosa working with anaconda python 3.8 and jupyter on Windows 10 (64) as follows...
Uninstalled anaconda (possibly it wasn't necessary to uninstall it - not sure)
Uninstalled jupyter the best I could (still seemed to be some remnants associated with arcpy)
Installed miniconda the python 3.8 version
Created a new (separate) Conda environment which also used python 3.8
This was done by opening the Conda command prompt then typing......
conda create --name signalpro38 python=3.8
(note that signalpro38 is the name I gave the new environment)
activated the new environment by typing:
conda activate signalpro38
Installed:
matplotlib,
scipy,
numba,
numpy
then
jupyter
into the new environment (signalpro38)
by typing
conda install matplotlib
conda install scipy
etc.
Added the new anaconda environment to jupyter by following the instructions here:
https://medium.com/#nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084
opened jupyter and created a new notebook (making sure to choose the name of the new environment signalpro38)
typed code into the new notebook, saved and ran it, to check that the commands
import matplotlib
and
import matplotlib.pyplot as plt
were working ok in jupyter
Closed jupyter and went back to the Conda command prompt (the signalpro38 environment that I had created was still activated)
then installed librosa using
pip install librosa
(note that "conda install librosa" didn't find librosa, however I imagine there is a way to install librosa using conda also)
opened jupyter again and the previously saved notebook file and added
import librosa
import librosa.display
all seems to be working well now! :)
Hopefully this will help someone else! most likely it will help me when I need to do this again one day! :p

OpenCV in Python using Pycharm [duplicate]

I have opencv-python installed and the .pyd file is added in the site-packages and the DLLs. The code works with images. When I want to read, show, write an image it works. But I get a warning that the functions' references cannot be found in init.py . Due to this, I can not use the auto-complete feature. Could someone help me out? I am using opencv 3.4.0 and python 3.6.4 in pycharm. I downloaded opencv via pip in the command prompt.
The problem is caused by CV2 and how __init__.py does the imports. Just ignore the warnings the program will work all the same, or you can do an import with an alias like:
import cv2.cv2 as cv2
If you have a warning on it press Alt+Enter to install and fix it. Now you will have the code completion and no other warnings (about that) on the project.
Switching to an older version of opencv solved this problem for me.
Apparently pycharm sometime breaks depending on the version of opencv. For me, the newest version was, 4.6.X unstalling and installing 4.5.X did the trick.
I use python 3.10 and my newest version for opencv is 4.6.0.66 ,by changing opencv version to 4.5.5.62 and with an alias: import cv2.cv2 as cv2 my problem has solved.
Import cv2 as follows:
from cv2 import cv2
I installed version 4.5.5.64 and imported with an alias.
import cv2.cv2 as cvv2
I was using Python 3.10.2288.0 and OpenCV 1.6.0.66.
I resolved the issue by rolling back the OpenCV version to 4.5.5.62.

How to import OpenCV into python

I have downloaded Anaconda on my Windows PC, and I have been using Spyder IDE. Now I want to do a project with OpenCV.
However, I have tried to install OpenCV using the Command Prompt and typing the following in:
pip install opencv-python
This only gives an error message and says "pip" is not recognized as a command.
Furthermore I tried to import OpenCV into Python using the following:
import cv2
This also doesn't work
I would appreciate any help in getting OpenCV working.
It depends on Your OS. Check Your pip installation with cmd: pip -V and check python with: python -V
It seems like You don't have pip installed at all.
Than import cv2 should work.

How to resolve this error of "Cannot find reference 'imread' in '__init__.py" in python after installing opencv?

I am new to python and installed opencv by typing: pip install opencv-contrib-python in the command prompt.
Below I have shown a very simple example of reading in an image and showing it on the screen:
However, I get this error:
When I hover over the imread method in PyCharm, it says Cannot find reference 'imread' in '__init__.py'
It was showing import and runtime errors when I typed import cv2 and import numpy in the command prompt.
I tried going back to the previous version of NumPy by typing pip install --force-reinstall numpy=1.19.3. So, now when I type import cv2 and import numpy in the command prompt, it shows no error but it says it still can't find a reference to it in PyCharm.
I am using Python 3.9.1 with pip 20.2.3.
If you are using python interpreter with anaconda change it to default python one. if you have not installed python separately then install it and assign the path to it.
somewhat this will be the path
c://user/APpData/Local/Programs/Python/python39/python.exe
The NumPy multicore import error is a result of installing NumPy on Windows that is incompatible with the version of OpenCV that you have. Judging from your screenshots as well as the error, you are running Windows. Try installing Christoph Gohlke's NumPy libraries instead that were built with multicore support enabled.
First do:
pip install pipwin
Then:
pipwin install numpy
This should hopefully settle the OpenCV dependency problem you have.
To solve it, you should upgrade numpy installation. Try:
pip install -U numpy
For information here
Instead of doing:
import cv2
try doing:
from cv2 import cv2
This worked for me after a lot of troubleshooting also using pycharm. I now have access to all of the regular cv2 methods.

What is the different between opencv-python library and cv2 library?

I am trying to use openCV. Normally, When I run command panel on desktop, I can see version of my openCV:
But when I couldn't import to my project. Normally, I was adding opencv-python library from interpreter but I builded cv2 library which version is 4.4.0 to use gpu. So I haven't got a opencv-python library at site-packages but I have cv2 file in site-packages. Unfortunately I couldn't import it to my project. How can I use this opencv version or file which name is cv2.cp37-win_amd64.pyd?
I can use all other libraries in site-packages. But when I couldn't add cv2 library. Here the a basic image read from file :
The interesting part of the problem is, all cv2 function cannot be found but program is working :D I am really confused.
cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.
The IDE probably doesn't recognize the cv2 commands because you are using a 64 bit version of opencv-python on a 32 bit version of Python or vice-versa. I believe this can be resolved by uninstalling your current OpenCV installation using pip uninstall opencv-python and then reinstalling it with the correct version following the linked tutorial.
Sources / Additional Links:
Install Tutorial: https://www.youtube.com/watch?v=Z78zbnLlPUA

Categories

Resources