[英]Import Error Python 2.7. No module named:
I'm receiving an ImportError when running my main script which is related to another script trying to import one of my modules and I'm unsure how to fix it. 我在运行主脚本时收到一个ImportError,这个脚本与另一个试图导入我的模块的脚本有关,我不确定如何修复它。 The layout of the files in relation to the software is as follows (folder names etc are fictional):
与软件相关的文件布局如下(文件夹名称等是虚构的):
poetry_generator/main.py
poetry_generator/architecture/experts/poetryexperts/sentence.py
poetry_generator/structures/word.py
Main.py is what I'm running, and the problem seems to arise from sentence.py trying to import word module and failing. 我正在运行Main.py,问题似乎来自于试图导入word模块并失败的sentence.py。
Currently in sentence.py I have: 目前在sentence.py我有:
from poetry_generator.structures.word import Word
Word is the name of the Class in word.py: Class Word(object). Word是word.py中Class的名称:Class Word(object)。 But I'm receiving the following error:
ImportError: No module named poetry_generator.structures.word
但是我收到以下错误:
ImportError: No module named poetry_generator.structures.word
Does anyone have any idea what is wrong? 有谁知道什么是错的? I have been readinga roudn similar questions already asked but nothing has worked so far.
我一直在阅读已经问过的类似问题,但到目前为止还没有任何工作。 Thanks in advance for any help.
在此先感谢您的帮助。
Full console text reagarding error: 完整的控制台文本重写错误:
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
The top-level project directory shouldn't be included in the module name. 顶级项目目录不应包含在模块名称中。 This should work:
这应该工作:
from structures.word import Word
You will need 你会需要
import sys
sys.path.insert(0, 'System/structures/word')
#or
sys.path.append('System/structures/word')
import Word
Otherwise you will need __init__.py
that you can make with these instructions . 否则,您将需要
__init__.py
,您可以使用这些说明 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.