我其中有2个软件包和主脚本:
$ ls package1
hello.py __init__.py
$ cat package1/hello.py
def runme():
print "Hello world"
$ ls package2
__init__.py someprogram.py
$ cat package2/someprogram.py
from package1.hello import runme
if __name__ == '__main__':
runme()
$ python package2/someprogram.py
Traceback (most recent call last):
File "package2/someprogram.py", line 1, in <module>
from package1.hello import runme
ImportError: No module named package1.hello
这是为什么?不应将当前目录添加到PYTHONPATH
并因此使package1
可以访问吗?