how to clear unresolved import 'cv2' error? - python

I have installed Python 3.9 on my ubuntu 18.04 desktop, i have already installed two libraries using pip3 install
1)opencv-contrib-python
2)opencv-python
Currently i am writing a program in VSCode for which i am importing cv2
I have already default version of python 3.6.9 in my computer. When i use default version as interpreter, program seems to be working fine.But if i switch the interpreter to newly installed python 3.9 , i get an error
ModuleNotFoundError: No module named 'cv2'
please someone who has faced such problem and know how to resolve it help me!!!...

The reason is as you described: it is due to the use of the Python environment.
The module "cv2" is installed in "lib\site-packages\" in python3.6.9, but when we use "python3.9" without the module "cv2" installed, VS Code is in "python3.9" The module could not be found in "lib\site-packages\".
You could use the command "pip3 --version" to check the source of the module installation tool, the module is installed in "lib\site-packages\" here:
When using the command "pip3 show opencv-python" to check its installation location: (...\python\python38\lib\site-packages)
Therefore, if you want to use the module "cv2" in "python3.9", please install it in this environment. In addition, it is recommended that you use a virtual environment, it will be stored in "lib\site-packages" in the folder of the project so that you could check it more intuitively.

Related

How can I solve the "ModuleNotFoundError: No module named 'psycopg2" problem?

I have a problem with VS Code. I think the problem ir related to the environment of the code.
Im trying to import the psycopg2 pool method (from psycopg2 import pool) after installing it with pip install psycopg2, and it says that ModuleNotFoundError: No module named 'psycopg2'
How can I fix it?
Press Ctrl+shift+p, type Python: Select Interpreter and choose the correct environment if it is an environment issue.
The packages installed in the python environment you have selected can work.
You can through pip show psycopg2 to know where have you installed the psycopg2.To know which python interpreter you have selected from the bottom-left on the VSCode.
And after you switch the python interpreter, remember to renew a terminal(shortcut Ctrl+Shift+`), the python extension will activate this python environment in the terminal, then the packages can be installed in the right place.

ModuleNotFoundError: No module named "dmidecode"

I have a python code that it has different packages like "dmidecode". I installed dmidecode using Python Interpreter successfully. But when I run the code, I receive this error:
import dmidecode
ModuleNotFoundError: No module named 'dmidecode'
Also, I installed dmidecode like this:
pip install dmidecode
But I received the same error again.
Would you please guide me what is wrong with installing dmidecode?
Any help is really appreciated.
did you check, whether your python interpreters (from your pycharm project and where you installed your packages) are the same?
Check if your package is in File/Settings/Project:"YourProjectName"/Python Interpreter All installed packages for this interpreter are listed there.
If it is not, you should change your python interpreter for that project

No module named 'cv2' even though it was successfully installed

I pip installed several packages (opencv, face_recognition, imutils)
They were all successfully installed, but are not recognized
I have a python script named script.py which imports cv2, but when I run it I get the following:
ModuleNotFoundError: No module named 'cv2'
I tried using pip list command to see the packages I have installed, but the packages I installed are not showing as you can see below.
I run pythonVersion.py to check my python version, it says it's using 3.8.2 which is where my packages are stored, as shown below.
I tried using #!/Users/Khuzama/opt/anaconda3/lib/python3.8 (the path of my packages) in my script, but still the same issue.
I am using jupyter notebook (anaconda navigator)
It is most probably the python environment you installed the packages are not the one you are currently referring to.
Try seeing the output of
which python
if this doesn't point to the anaconda one, then navigate to Users/Khuzama/opt/anaconda3/lib/python3.8 and run your script from there. Alternatively you can link the python from anaconda as the main python for your system

import dlib ModuleNotFoundError: No module named 'dlib' in python IDLE

I have installed dlib using Anaconda 3 prompt.
It has shown me that it got installed successfully. I checked through command import dlib it did not give me any error even I checked the version also it came up with 19.9.0.
But when I open my program in IDLE and run the program its showing me error
import dlib ModuleNotFoundError: No module named 'dlib'
Even from command prompt, I am getting same error.
What is the issue? I am using Python 3.6.
Installation process of dlib using anaconda3:
You have installed the package in different version of python and importing the package in other version of the python.
Package is installed. in virtual environment(3.6.8) and is being imported in standard system python (3.6.0).
So either you need to use this virtual environment for your application otherwise you will need to install the package into global system python.
Extending #Rohit's answer:
As you have installed dlib in Anaconda, you need to run the program using Anaconda prompt.
By default, IDLE and python command in command prompt use Python that is installed system wide (which is Python 3.6.0 in your case).
But to use dlib which is installed in Anaconda's virtual environment (env_dlib) you need to do:
Open Anaconda prompt.
Activate env_dlib environment: activate env_dlib
Run the Python file which uses dlib package: python FILENAME

trouble with importing python modules

I am trying to import Python packages that I had previously installed but I keep getting this error when trying to import it
"ImportError: No module named gdal"
In the images attached (in the link :P) you can see that the package python-gdal and python-numpy are installed. I am also attaching the python output.
P.S = I am using Ubuntu and running python from the terminal.
You have possibly installed a non-Ubuntu version of Python - Anaconda - yet these packages are installed into the system Python. You should probably remove Anaconda, and/or run the system Python explicitly as /usr/bin/python.

Categories

Resources