简体   繁体   English

ImportError:没有名为b的模块-Python

[英]ImportError: No module named b - Python

I was stuck with a code in python. 我陷入了python代码中。 But in simple form it looks like this 但是以简单的形式看起来像这样

a.py looks like this a.py看起来像这样

import b

def hello():
  print "hello"

print "a.py"
print hello()
print b.hi()

and b.py looks like this 和b.py看起来像这样

def hi():
  print "hi"

a.py , i get an error. a.py,我收到一个错误。 I know a couple of questions that address circular dependancies. 我知道几个有关循环依赖的问题。 But this is not that case correct? 但这不是正确的情况吗? TIA - Edited TIA-编辑

I've had a problem like this before and it was because I did not have an __init__.py in the same directory as the module/package I was trying to import. 我以前遇到过这样的问题,这是因为我在与要导入的模块/包相同的目录中没有__init__.py You need that file in order to import a package even if it's empty. 您需要该文件才能导入软件包,即使它是空的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM