import cv2 doesn't give error on command-Prompt but error on IDLE on Windows 10, Python 3.6.4 - python-3.x

I have Installed Python 3 (32bit) on Windows.
I have read this answer, but I can't install cv2 using
pip install opencv_python-3.4.1-cp37-cp37m-win32.whl and it gives error as
opencv_python-3.4.1-cp37-cp37m-win32.whl is not a supported wheel on this platform.
when I tried Python shell, and run the command import cv2 it doesn't give error,
but when I try it as import cv2 in IDLE terminal, then It gives error as
>>> import cv2
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'

You could also install opencv in these three easy steps
Type py -m pip install opencv-python
In the same window type python or open IDLE python.
Now type import cv2.
there you go... simple and easy i hope it helps.

1)Download OpenCV from here
2)Extract the zip file to Root drive(mostly 'C'Drive)
3)Goto folder opencv\build\python\2.7\x86 and copy cv2 file to your main Python directory,
in my case Python directory is
C:\Users\Deshmukh Brothers\AppData\Local\Programs\Python\Python36-32\Lib\site-packages
and paste cv2 file there.
4)Run command as python -m idlelib and now it will prompt idle-shell.
5)now it will work as import cv2, it nothing occurred and cursor went to next line then it is successfully installed.

Related

Python package pypdf2 is "already installed" but can not import it

I am a newbie with Python and I am going around in circles over python's inability to find a mod. In jupyter notebook here is what I get:
pip install pypdf2
Requirement already satisfied: pypdf2 in c:\users\stanleydenman\appdata\local\programs\python\python311\lib\site-packages (3.0.1)
Note: you may need to restart the kernel to use updated packages.
import pypdf2
import pypdf2
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 1
----> 1 import pypdf2
ModuleNotFoundError: No module named 'pypdf2
So python acknowledges pypdf2 is installed, but cannot find it to import it? I
I have installed, and reinstalled python. I selected the option once to have environmental variables set, other times set them myself. Nothing makes a difference.
Environmental variable set as follows:
C:\Users\StanleyDenman\AppData\Local\Programs\Python\Python311\Scripts\site-packages;C:\Users\StanleyDenman\AppData\Local\Programs\Python\Python311\;C:\Users\StanleyDenman\AppData\Local\Microsoft\WindowsApps;C:\Users\StanleyDenman\AppData\Roaming\npm;C:\Users\StanleyDenman\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Tesseract-OCR;
Tried with Anaconda, cmd line, and jupyter notebook. All the same result.
Try pip list to make sure it's installed.

64bit MacOs After succesfully installing Pygame: ModuleNotFoundError: No module named 'pygame'

Python noob here. I've been trying to install pygame and pandas for a few hours now. Even with Conda I did not succeed. I have Python 3.8.5 installed.
I eventually tried through the terminal with these commands:
python -m pip install pygame==2.0.0.dev6
and
python -m pip install pandas
(this was a total guess by the way, but apparently it did something)
Results were succesfull:
Requirement already satisfied: pygame==2.0.0.dev6 in /opt/miniconda3/lib/python3.8/site-packages (2.0.0.dev6)
and
Successfully installed numpy-1.19.2 pandas-1.1.2 python-dateutil-2.8.1 pytz-2020.1
But, when I try to import either modules, I still get errors. Any ideas?
import pygame
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
import pandas
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
Do I need to move the modules to the script folder or something? Or what do I even move? Thanks!
Ok.. Got it thanks to #matt.. after succesfully installing pygame, find the environment in which pygame is installed by entering 'which python'.
In my case it returned:
/opt/miniconda3/bin/python
Now I needed to make sure the VS console was pointing at the same environment, by checking which python interpreter it was using and selecting the correct one. More info:
how to check and change environment in VS Code

import module error python3 xubuntu 19.04

When importing PyGame using the interpreter it is successful. Using Geany it is not.
shows the error.
I have tried editing the shebang, renaming the file. making sure the PATH and version were correct, and that there were no missing Geany plugins.
import pygame
pygame.init()
Error in Geany:
Traceback (most recent call last):
File "moduleerror.py", line 3, in <module>
import pygame
ImportError: No module named pygame
I went into Build >> Set Build Commands and under Execute commands changed
python "%f"
to
python3 "%f"

Cannot access built-in webcam Python

I'm trying to access my laptop webcam and from what I have seen, I need to use the cv2 package. I downloaded it from PyPi but the contents of the file seem to be missing a lot of content as it only has __init__.py, cv2.cp36-win32.pyd, and opencv_ffmpeg320.dll. So whenever I try use things such as VideoCapture and imwrite, it says it cannot find a reference to them.
When I run the application, I get the following error message:
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
File "C:/Users/RedCode/PycharmProjects/FunApps/ImageFile.py", line 1, in <module>
import cv2
File "C:\Users\RedCode\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cv2\__init__.py", line 7, in <module>
from . import cv2
ImportError: numpy.core.multiarray failed to import
I have got the numpy package installed and imported but it didn't fix the issue so I'm guessing that's not the actual cause of the problem, so I'm certain it must have something to do with the cv2 package.
The code I'm using right now is as follows:
import cv2
import numpy
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
rval, frame = vc.read()
else:
rval = False
while rval:
cv2.imshow("preview", frame)
rval, frame = vc.read()
key = cv2.waitKey(20)
if key == 27: # exit on ESC
break
cv2.destroyWindow("preview")
I'm also using Python 3.6 and Windows 10 if that helps with anything.
How can I get my application to work?
In your case you can solve your problem by using the following command:
pip install -U numpy
Check existing package:
pip show numpy
And upgrade it via:
pip install numpy --upgrade
Check the path if you still got error:
> import numpy
> print numpy.__path__
You must install the latest version of numpy. Use the command pip install numpy --upgrade or you can just download the wheel file from http://www.lfd.uci.edu/~gohlke/pythonlibs/ . Just check for your python version and platform and download the necessary wheel file. Next use pip to install the wheel file.

Scipy install help windows 10

I am trying to get scipy running on my computer and I have been fighting for the last few hours with it. Currently, im running python 3.6 and I am on windows 10. I first tried to install it using pip which failed no matter what I did. Then I went and downloaded the wheel file and installed it manually using pip. Then I used pip to get the rest of the dependencies like the website stated pip install --user numpy scipy matplotlib ipython jupyter pandas sympy nose. It installed the rest of the packages just fine.
If I say in IDEL
import scipy
It will give me an error of
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
from scipy import special, optimize
File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\__init__.py", line 116, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36-32\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
if I go in that file to comment out that line, it will import but it after that I get a lot more errors anytime I try and do anything.
Also, I tried installing anaconda as a dependency manager and that seemed to work fine for installing, but if I tried to used Atom or IDLE as my text editor it can't seem to find scipy when its compiling and throws and error. I am kinda at a loss and any advice or help on this would be much appreciated. Thank you in advance.

Resources