当尝试在python 3.4中导入我的模块时,我得到:
In [6]: import PyModLSM
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-9980d6d1561d> in <module>()
----> 1 import PyModLSM
/home/naught101/Documents/uni/phd/projects/ModularLSM/PyModLSM/PyModLSM/__init__.py in <module>()
11 sys.exit()
12
---> 13 from . import handlers
14 from . import models
15 from . import constants
ImportError: cannot import name 'handlers'
目录结构是:
├── LICENSE.md
├── PyModLSM
│ ├── component.py
│ ├── constants.py
│ ├── data.py
│ ├── functions.py
│ ├── handlers.py
│ ├── __init__.py
│ ├── models.py
│ └── science_functions.py
├── README.md
└── setup.py
据我所见,没有循环导入:
$ grep -irH "from.*import" PyModLSM/*py
PyModLSM/functions.py: from .handlers import ModelHandler
PyModLSM/handlers.py:from .component import ModelComponent
PyModLSM/__init__.py:from . import handlers
PyModLSM/__init__.py:from . import models
PyModLSM/__init__.py:from . import constants
PyModLSM/__init__.py:from . import science_functions
PyModLSM/__init__.py:from .functions import *
PyModLSM/models.py:from .component import ModelComponent
PyModLSM/models.py:from . import science_functions as sf
PyModLSM/science_functions.py:from . import constants as c
自从我升级到python 3.4(使用conda)以来,这已经开始发生了 - 我之前在python 3.3上,或者可能是3.2,并且它工作正常。
答案 0 :(得分:3)
叹息..好吧,这是由于缺少必需的模块,平均时间安装并导入。 Python拒绝导入处理程序,因为之前缺少该模型。重新启动Python允许导入正常继续。
不确定是否应删除此问题,或留待此处以防其他人做同样的事情。
答案 1 :(得分:-1)
您是否识别出错误行
PyModLSM / models.py:from .component import ModelComponent
可能应该是
来自。组件导入ModelComponent