导入错误 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 就是我 运行,问题似乎是 sentence.py 试图导入 word 模块但失败了。
目前在 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
你需要
import sys
sys.path.insert(0, 'System/structures/word')
#or
sys.path.append('System/structures/word')
import Word
否则你需要 __init__.py
,你可以用 these instructions 制作。
顶级项目目录不应包含在模块名称中。这应该有效:
from structures.word import Word
当我的主脚本 运行 与尝试导入我的模块之一的另一个脚本相关时,我收到一个 ImportError,我不确定如何修复它。与软件相关的文件布局如下(文件夹名称等均为虚构):
poetry_generator/main.py
poetry_generator/architecture/experts/poetryexperts/sentence.py
poetry_generator/structures/word.py
Main.py 就是我 运行,问题似乎是 sentence.py 试图导入 word 模块但失败了。
目前在 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
你需要
import sys
sys.path.insert(0, 'System/structures/word')
#or
sys.path.append('System/structures/word')
import Word
否则你需要 __init__.py
,你可以用 these instructions 制作。
顶级项目目录不应包含在模块名称中。这应该有效:
from structures.word import Word