Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix the "__path__ attribute not found" error for packages installed by pip installer?

Tags:

python

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?

like image 615
kareemostafa Avatar asked Jan 12 '19 15:01

kareemostafa


People also ask

Why can't I see all the packages installed by Pip?

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?

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 ...

How to fix pip install error in Windows 10?

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.

Why can’t I find the Python module in Pip?

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.


1 Answers

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.

like image 191
Emma Avatar answered Sep 23 '22 06:09

Emma