繁体   English   中英

导入错误Python 2.7。没有命名的模块:

[英]Import Error Python 2.7. No module named:

我在运行主脚本时收到一个ImportError,这个脚本与另一个试图导入我的模块的脚本有关,我不确定如何修复它。 与软件相关的文件布局如下(文件夹名称等是虚构的):

poetry_generator/main.py

poetry_generator/architecture/experts/poetryexperts/sentence.py

poetry_generator/structures/word.py

我正在运行Main.py,问题似乎来自于试图导入word模块并失败的sentence.py。

目前在sentence.py我有:

from poetry_generator.structures.word import Word

Word是word.py中Class的名称:Class Word(object)。 但是我收到以下错误: ImportError: No module named poetry_generator.structures.word

有谁知道什么是错的? 我一直在阅读已经问过的类似问题,但到目前为止还没有任何工作。 在此先感谢您的帮助。

完整的控制台文本重写错误:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    from architecture.control_component import ControlComponent
  File "/home/lee/Downloads/PoEmo-master/poetry_generator/architecture/control_component.py", line 4, in <module>
    from experts.poem_making_experts import exclamation_expert
  File "/home/lee/Downloads/PoEmo-master/poetry_generator/architecture/experts/poem_making_experts/exclamation_expert.py", line 5, in <module>
    from poetry_generator.structures.word import Word
ImportError: No module named poetry_generator.structures.word

顶级项目目录不应包含在模块名称中。 这应该工作:

from structures.word import Word

你会需要

import sys
sys.path.insert(0, 'System/structures/word')
#or
sys.path.append('System/structures/word')

import Word

否则,您将需要__init__.py ,您可以使用这些说明

暂无
暂无

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

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