[英]Ubuntu 16.04 python can not import my modules
I've got a folder named aspects where there are 2 files: Aspects.py and Main.py. 我有一个名为Aspects的文件夹,其中有2个文件:Aspects.py和Main.py。 I'm using the class from Aspects.py in Main.py.
我正在使用Main.py中Aspects.py中的类。 There is a line
from aspects.Aspects import Aspects
there and on Mac OS I've got no problems running my program. from aspects.Aspects import Aspects
有一条线from aspects.Aspects import Aspects
,在Mac OS上,我的程序运行没有问题。 But I need to run it on Ubuntu, so I do this: 但是我需要在Ubuntu上运行它,所以我这样做:
python3 Main.py
but get the problem: 但出现问题:
Traceback (most recent call last):
File "Main.py", line 1, in <module>
from aspects.Aspects import Aspects
ImportError: No module named 'aspects'
Please, help me! 请帮我!
If your aspects
folder structure as follows: 如果您的
aspects
文件夹结构如下:
- aspects/
- __init__.py
- Aspect.py
- Main.py
To import Aspect module into your main: 要将Aspect模块导入您的主模块:
#Main.py
from . import Aspect
Aspect.classname
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.