ModuleNotFoundError: No module named '__main__.detector'; '__main__' is not a package

本文介绍了一种常见的Python模块导入错误及其解决方案。错误为尝试从非包路径导入模块导致,通过调整文件位置并使用正确的包路径引用解决了问题。此外,还提供了一个InsightFace模型Pytorch版本的参考链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是我原本的目录结构,我想在test_on_images中

from .detector import detect_faces

结果报了No module named '__main__.detector'; '__main__' is not a package

解决方法:将test_on_images移动到insightface文件夹的上一层,然后修改成

from insightface.detector import detect_faces

就ok了!

github参考链接

附一个InsightFace模型pytorch版的链接:https://github.com/TreB1eN/InsightFace_Pytorch/tree/master/mtcnn_pytorch

(venv) E:\pycharm\study\dorm_face_recognition\model_training>pip install dlib Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting dlib Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/f4/f8949b18ec1df2ef05fc2ea1d1dd82ff2d050b8704b7d0d088017315c221/dlib-20.0.0.tar.gz (3.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.3/3.3 MB 6.6 MB/s eta 0:00:00 Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... done Building wheels for collected packages: dlib Building wheel for dlib (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for dlib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [48 lines of output] running bdist_wheel running build running build_ext Traceback (most recent call last): File "E:\python3.9.13\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "E:\python3.9.13\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "E:\pycharm\study\venv\Scripts\cmake.exe\__main__.py", line 4, in <module> ModuleNotFoundError: No module named 'cmake' ================================================================================ ================================================================================ ================================================================================ CMake is not installed on your system! Or it is possible some broken copy of cmake is installed on your system. It is unfortunately very common for python package managers to include broken copies of cmake. So if the error above this refers to some file path to a cmake file inside a python or anaconda or miniconda path then you should delete that broken copy of cmake from your computer. Instead, please get an official copy of cmake from one of these known good sources of an official cmake: - cmake.org (this is how windows users should get cmake) - apt install cmake (for Ubuntu or Debian based systems) - yum install cmake (for Redhat or CenOS based systems) On a linux machine you can run `which cmake` to see what cmake you are actually using. If it tells you it's some cmake from any kind of python packager delete it and install an official cmake. More generally, cmake is not installed if when you open a terminal window and type cmake --version you get an error. So you can use that as a very basic test to see if you have cmake installed. That is, if cmake --version doesn't run from the same terminal window from which you are reading this error message, then you have not installed cmake. Windows users should take note that they need to tell the cmake installer to add cmake to their PATH. Since you can't run commands that are not in your PATH. This is how the PATH works on Linux as well, but failing to add cmake to the PATH is a particularly common problem on windows and rarely a problem on Linux. ================================================================================ ================================================================================ ================================================================================ [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Failed to build dlib ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值