【发布时间】:2025-12-12 12:30:30
【问题描述】:
我最近使用 pip install 安装了 opencv 包,并编写了一个小代码来测试它(cvtest.py)。该代码通过 python idle shell 运行,但在命令提示符下运行它会给出错误
Error while finding module specification for 'cvtest.py' (ModuleNotFoundError: __path__ attribute not found on 'cvtest' while trying to find 'cvtest.py')
我尝试卸载并重新安装 python 和包。使用python -m site 查找系统路径会给出这些结果。我是笔记本电脑的唯一用户。
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',
这是我正在使用的代码
import cv2
x=cv2.imread('backpack for sale.jpg',0)
cv2.imshow('x',x)
更新:无论是否需要导入,我拥有的所有 py 文件都存在问题。显然python正在为所有文件寻找_init_.py,就好像它们是包一样。知道发生了什么吗?
【问题讨论】:
标签: python