导入错误:没有模块名为PBA的

问题描述:

我想申请从GitHub这个OpenCV的项目: https://github.com/andrewssobral/simple_vehicle_counting导入错误:没有模块名为PBA的

我在Linux上使用Python是这样去了,这是我遇到麻烦进口线:

from __future__ import print_function 
import cv2 

import analysis 
import tracking 
import bgs.pbas as pbas 

最后一行是一个导致此错误: the error message

Traceback (most recent call last): 
    File "./build/python/demo.py", line 6, in <module> 
    import bgs.pbas as pbas 
    File "/home/user/Downloads/simple_vehicle_counting-master/build/python/bgs/pbas/__init__.py", line 1, in <module> 
    from pbas import * 
ImportError: No module named pbas 

和是的PBA的init文件中的代码:

from pbas import * 

# noinspection PyUnresolvedReferences 
import pyboostcvconverter as pbcvt 

注:其它进口像第一个import analysis工作正常,即使在init文件非常相似,这是分析的init文件:

from analysis import * 

# noinspection PyUnresolvedReferences 
import cvb 
# noinspection PyUnresolvedReferences 
import pyboostcvconverter as pbcvt 
+0

这不完全是什么'__init__'为bgs.pbas里面当我看。我看到'import _pbas'。不知道为什么你有不同的东西,但那个小小的下划线可能会解释一些事情。 – RobertB

导入不会在程序的名称空间中查找,因此您必须执行from bgs.pbas import *。它不知道你已经将bgs.pbas导入为pbas。更多关于巨蟒哪里查找模块导入这里:

https://docs.python.org/2/tutorial/modules.html#the-module-search-path

+0

对不起,我没有得到0_0。你能解释更多吗? 我的意思是,为什么可以写'导入分析'而不是'import bgs.pbas as pbas' –

+0

它工作正常,但我只想知道为什么? –

+0

@AmerAlahmar将'bgs.pbas导入为pbas'是可以的。这将bgs.pbas作为pbas放在程序的命名空间中。导入并不检查程序的命名空间,所以当你想从它导入*时,你需要使用它的全名:'from bgs.pbas import *',而不是'from pbas import *'。 – dogoncouch