gpt4 book ai didi

python - 相对导入的问题

转载 作者:太空宇宙 更新时间:2023-11-03 21:15:53 27 4
gpt4 key购买 nike

我运行一个名为 test.py 的文件,它具有这样的导入

from .nms.cpu_nms import cpu_nms, cpu_soft_nms
from .nms.gpu_nms import gpu_nms

当我运行该文件时,我收到此错误:

Traceback (most recent call last):
File "test.py", line 9, in <module>
from utils.nms_wrapper import nms
File /media/ryan/shakira/InsightFace_Pytorch/FaceBoxes.PyTorch/utils/nms_wrapper.py", line 7, in <module>
from .nms.cpu_nms import cpu_nms, cpu_soft_nms
ModuleNotFoundError: No module named 'utils.nms.cpu_nms'

我尝试过这样做

sys.path.append('/path/to/the/main/directory/')

但这也行不通,

编辑:

这是我的目录结构:

FaceBoxes.PyTorch/
├── data
│   ├── AFW
│   │   └── img_list.txt
│   ├── config.py
│   ├── data_augment.py
│   ├── FDDB
│   │   └── img_list.txt
│   ├── __init__.py
│   ├── PASCAL
│   │   └── img_list.txt
│   ├── __pycache__
│   │   ├── config.cpython-36.pyc
│   │   ├── data_augment.cpython-36.pyc
│   │   ├── __init__.cpython-36.pyc
│   │   └── wider_voc.cpython-36.pyc
│   ├── WIDER_FACE
│   │   └── img_list.txt
│   └── wider_voc.py
├── layers
│   ├── functions
│   │   ├── prior_box.py
│   │   └── __pycache__
│   │   └── prior_box.cpython-36.pyc
│   ├── __init__.py
│   ├── modules
│   │   ├── __init__.py
│   │   ├── multibox_loss.py
│   │   └── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   └── multibox_loss.cpython-36.pyc
│   └── __pycache__
│   └── __init__.cpython-36.pyc
├── LICENSE
├── make.sh
├── models
│   ├── faceboxes.py
│   └── __init__.py
├── README.md
├── test.py
├── train.py
└── utils
├── box_utils.py
├── build.py
├── __init__.py
├── nms
│   ├── cpu_nms.c
│   ├── cpu_nms.pyx
│   ├── gpu_nms.cpp
│   ├── gpu_nms.hpp
│   ├── gpu_nms.pyx
│   ├── __init__.py
│   ├── nms_kernel.cu
│   ├── __pycache__
│   │   └── __init__.cpython-36.pyc
│   └── py_cpu_nms.py
├── nms_wrapper.py
├── __pycache__
│   ├── box_utils.cpython-36.pyc
│   ├── __init__.cpython-36.pyc
│   └── nms_wrapper.cpython-36.pyc
└── timer.py

任何建议都会非常有帮助,提前致谢。

最佳答案

导入中没有错误,问题是有一个我必须编译的 cython 文件,我已经掩盖了它。编译后,问题就消失了。

关于python - 相对导入的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54722814/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com