相对导入问题

时间:2019-02-16 11:58:25

标签: python cython python-import pytorch

我运行了一个名为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

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

1 个答案:

答案 0 :(得分:0)

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

相关问题