No module found cv2 in IDLE - python

I am trying to install opencv3.0 on my ubuntu system. I installed it according to link : http://www.pyimagesearch.com/2015/06/22/install-opencv-3-0-and-python-2-7-on-ubuntu/#comment-429946
At the end, in the terminal,when I try to import cv2, it works. But in the python IDLE it does not work. It gives the error : "No module named cv2".
Also, whenever I try to enter workon cv command, it says : "Error: deactivate must be sourced. Run 'source deactivate'instead of'deactivate'."
Althoug it gives error, I can get in cv environment((cv) ali#ali-pc:~$ ).
I am new to ubuntu and opencv. Thanks

Maybe its because of your IDLE interpreter settings. I use Pycharm and set to project interpreter path to my virtualenv interpreter with installed opencv-python. After this import works.

Try by giving version
pip install opencv==4.1.0.25(latest version)
Check
pip list
If not listed search location of python
which python
Search for site-packages folder inside resultant location of 'python' (usually under lib/python3.5/site-packages) and check if opencv-python present or not(packages are not installing right location)
sudo apt-get install opencv-python

Related

How to fix an error about PATH when installing tensorflow on windows?

I tried to install tensorflow, but I got the following error:
My Command:
pip install tensorflow
The Error I got:
ERROR: Could not install packages due to an OSError:
[Errno 2] No such file or directory:
'C:\\Users\\sipha\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0
\\LocalCache\\local-packages\\Python310\\site-packages\\tensorflow\\include
\\external\\com_github_grpc_grpc\\src\\core\\ext\\filters\\client_channel
\\lb_policy\\grpclb\\client_load_reporting_filter.h'
HINT: This error might have occurred since this system does not have
Windows Long Path support enabled. You can find information on how to
enable this at https://pip.pypa.io/warnings/enable-long-paths
anyone know how to make new envirenment?
install tensoCMDrflow on windows, worked with CMD.
have python version 3.10
It seems like Long Path is disabled on your PC.
Do the following to enable it, and then try to install Tensorflow.
Press the Windows key + R key.
Type regedit and press enter.
Navigate to the following location Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem in the registry editor(regedit), or you could just paste it in the search bar on top.
Find and right click on LongPathsEnabled
Set the DWORD value to 1 instead of zero and reboot your computer.
This will enable Long Path support. Then try to install Tensorflow again.
You could reference the following article if you need any help https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/.
try conda install instead of pip install if you have conda installed
conda install tensorflow==2.6.0

ImportError: DLL load failed while importing cv2

When I install OpenCV, I get an error as shown below. What should I do?
ImportError: DLL load failed: The specified module could not be found.
Installing OpenCV
To install a package in Jupyter Notebook, you can use the magic %pip command.
%pip install opencv-python
If the above command doesn't work on IPython < 7.3, you can try this command instead.
!pip install --user opencv-python
Demonstration
Let's see it in action. First, you insert a new cell, type in either of the two commands above, and then execute the cell using the Ctrl + Enter shortcut.
You should now be able to import and use OpenCV without any errors.
This is usually a dependency issue. Just .pyd is not enough (all .DLLs are required).
On Windows add entries to .dll into PATH environment variable (not enough for Python 3.8 with updated security policies)

ModuleNotFoundException youtube-dl module is not recognized

i have installed the youtube-dl module via pip with pip install youtube-dl and it worked. I can use it in CMD but for some weird Reason Python says that the Module doesnt exist:
Extension 'cogs.music' raised an error: ModuleNotFoundError: No module named 'youtube_dl'
this problem usually happens when there is more than one python version on the computer, download the modules according to the version you want to use
if this is didn't work for us do like bottom steps
go your python libs path and look up you must got this ........\lib\site-packages\youtube-dl
if you havn't got, go pypi site and download packets
after that, take out this file to ......\lib\site-packages
you should see like this :
or you can do like this:go your python path and open cmd and start writing:
......\python.exe -m pip install youtube_dl
Try the following command.
pip3 install --upgrade youtube-dl

Visual Studio Code is rejecting the Tensorflow installation in a Virtual Environment

I created a virtual environment called env using
python -m venv env
.\env\Scripts\activate.bat
pip install tensorflow
I verified tensorflow is in the env\Lib\site-packages folder
Next I loaded VS Code and created a workspace, added a python file, it prompted me to install pylint,
I typed in python: select interpreter and I browsed to C:\Users\admin\env\Scripts folder
This is the command line at the beginning of the script
(env) PS C:\Users\admin\env\project> cd 'c:\Users\admin\env\project'; & 'C:\Users\admin\env\Scripts\python.exe' 'c:\Users\admin\.vscode\extensions\ms-python.python-2020.8.106424\pythonFiles\lib\python\debugpy\launcher' '54436' '--' 'c:\Users\admin\env\project\face_gan.py'
This is the error I get when debugging the python file:
ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`
PS C:\Users\admin\env\project> & C:/Users/admin/env/Scripts/Activate.ps1
When I type in pip install tensorflow in VS Code terminal, it shows its already installed
(env) PS C:\Users\admin\env\project> pip install tensorflow
Requirement already satisfied: tensorflow in c:\users\admin\env\lib\site-packages (2.3.0)
I don't understand this, is it not running in virtual environment?
Why is it executing C:/Users/admin/env/Scripts/Activate.ps1 at the end of the debugging session, not at the beginning
Lastly, is running python from the virtual environment folder C:\Users\admin\env\Scripts the same as using the activate.bat file or the source command? Does it automatically defer to using the C:\Users\admin\env\Lib folder, or is it still trying to use the default python installation to look for Tensorflow?
What step did I miss to make it use the virtual environment correct in VS Code?
First question: executing C:/Users/admin/env/Scripts/Activate.ps1 after debugging command make no difference. It just because it's the first command of the terminal. You can run it again to make a try.
Second question: Yes, that's the same. In your case, it will add 'C:\Users\admin\env' and 'C:\Users\admin\env\lib\site-packages' path to the PYTHONPATH variable.
You can through these codes to get the PYTHONPATH(the default search path for module files) variable value:
import sys
print(sys.path)
If you import 'tensorflow' directly. you will find you can import it correctly. It's a version problem. You should downgrade the version of the packages, and you can refer to this comment to get some useful information.

Python: changing directory of Python package for development

Suppose I have a python package in following directory:
c:\Python27\site-package\monster
I want to change it to local branch:
c:\ddey\dev
I went to the directory c:\ddey\dev where I have \monster developer package
and tried: pip install -e .
But it isn't changing the path. How do I know?
in python I tried following:
>>>import monster
>>>print(monster.__file__)
c:\Python27\site-package\monster\__init__.pyc
expected:
>>>import monster
>>>print(monster.__file__)
c:\ddey\dev\monster\__init__.pyc
solution:
previously my pip install was getting completed but I never getting the following message at the end of it as shown below. There was an issue with a package during the operation which I didn't notice as pip install wasn't giving a clear error.Once I fixed the issue with the package, the installation worked fine and got expected result!
Successfully installed monster
Try using pip install --target=d:\path\not_default package_name

Categories