how to fix the "__path__ attribute not found" error for packages installed by pip installer?
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?
Solution 1:
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.