【发布时间】:2015-11-19 21:38:24
【问题描述】:
我在how to import from a subfolder 上看到过提示。问题是从同一父文件夹中的另一个文件夹导入。目前的结构是这样的:
test
__init__.py
|-- folder1
|-- __init__.py
| |-- A.py
|-- folder2
| |-- __init__.py
| |-- B.py
A.py 是:
hi = 1
print "hi", hi
B.py 是:
from folder1 import A
print "imported"
当我做python B.py 时,我得到一个错误:
File "B.py", line 1, in <module>
from folder1 import A
ImportError: No module named folder1
如何导入 A.py?理想情况下,文件夹结构不会改变。
【问题讨论】:
-
什么python版本?
-
python 路径是什么?
-
python 版本 2.7,我在我的主目录 /Applications/anaconda/bin/python 中使用 anaconda python
标签: python python-import