I recently installed the opencv package using pip install and I wrote a small code to test it (cvtest.py). The code runs through the python idle shell but running it though the command prompt gives the error
Error while finding module specification for 'cvtest.py' (ModuleNotFoundError: __path__ attribute not found on 'cvtest' while trying to find 'cvtest.py')
I tried uninstalling and reinstalling both python and the package. looking up the system path using python -m site
gives these results. I am the only user of my laptop.
sys.path = [ 'C:\\Users\\Kareem Mostafa\\Desktop\\Assignments\\computer vision', 'G:\\Python37\\python37.zip', 'G:\\Python37\\DLLs', 'G:\\Python37\\lib', 'G:\\Python37', 'G:\\Python37\\lib\\site-packages',
This is the code I am using
import cv2 x=cv2.imread('backpack for sale.jpg',0) cv2.imshow('x',x)
update: the problem is happening with all the py files I am having whether they require imports or not. apparently python is looking for _init_.py
for all the files as if they are packages. Any idea what is going on?
I think the problem is due to the fact you have more than one version of python installed. Package installed by pip are visible to one version, but not to the other. I think this issue is quite common, and has already been answered (for example) here: Too many different Python versions on my system and causing problems
How To Fix Could Not Install Packages Due To An Environmenterror: [winerror 5] Access Is Denied Error When Install Python Module In Windows 1. Run Windows Powershell As Admin. Right-click the start button at windows 10 bottom left corner. Then click Windows... 2. Run Pip Install Command With –user ...
1 Run Windows Powershell As Admin. Right-click the start button at windows 10 bottom left corner. ... 2 Run Pip Install Command With –user Argument. You can also fix this error by add –user argument to the pip command that you need to execute like below. ... 3 Question & Answer.
This may work if you have multiple versions of python installed, one of them being Python3. One special case you may find yourself in is that the python module used to exist and, for whatever reason, no longer is part of PIP. In this case there is but one solution I have found. This is to try and find a .whl or wheel package for the python module.
For anyone else that had this problem (assuming kareemostafa has fixed it now!)
Removing the .py
suffix on the python -m
command fixes this problem, it appears -m
only requires module names whereas running it directly as a python file (no -m
option) requires the .py
suffix
In your case python -m cvtest
should be sufficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With