【发布时间】:2016-03-31 10:35:42
【问题描述】:
我是 Python 新手,我试图理解一个问题,我在创建包时看到了这个问题。 我有以下文件结构:(工作目录是/my/Python/jmLib2)
/my/Python/jmLib2
|--- Phone
| |--- __init__.py
| |--- Pots.py
|- Test2.py
---------------------------------
cat ./jmLib2/Pots.py
#!/usr/bin/python
def Pots():
print ("I'm Pots Phone")
---------------------------------
cat ./jmLib2/__init__.py
from Pots import Pots
---------------------------------
cat ./Test2.py
#!/usr/bin/python
from Phone import Pots
import os.path
print ("OS:"+str(os.path))
Pots()
当我现在这样做时:
python2 Test2.py
OS:<module 'posixpath' from '/usr/lib/python2.7/posixpath.pyc'>
I'm Pots Phone*
太棒了...但是,如果我这样做了:
python3 Test2.py
Traceback (most recent call last):
File "Test2.py", line 2, in <module>
from Phone import Pots
File "/home/juergen/my/Python/jmLib2/Phone/__init__.py", line 1, in <module>
from Pots import Pots
ImportError: No module named 'Pots'
我在 Eclipse 下使用 PyDev。 PyDev 在 init.py 文件中向我报告“未解决的导入:Pots”错误。 我在 PyDev 和 bash 下也有同样的回溯问题。
再说一次,我是 Python 新手……所以这可能是一个非常愚蠢的错误。 但是有人可以解释一下,python2 和 python3.4 之间的区别吗? 我必须修改 PYTHONPATH 吗?为什么?
问候 于尔根
【问题讨论】:
标签: python package importerror