7

I'm fairly new to Python, and I'm working on creating my first simple package. Here's my structure:

Math/
    __init__.py
    divide.py
    minus.py
    multiply.py
    plus.py

Each of the four files has a simple mathematical function declared. My init file is simply

from plus import *
from minus import *
from multiply import *
from divide import *

When I try to "import Math", however, I get the following error:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import Math
  File ".\Math\__init__.py", line 1, in <module>
    from plus import *
ImportError: No module named 'plus'

And yes, I know my package has to be in the correct folder; if I move any one of my files outside of the Math folder and run the import call on it by itself from the shell it works just fine.

4

1 回答 1

10

您正在使用 Python 3,它需要在包内进行相对导入。

from .plus import *
from .minus import *
from .multiply import *
from .divide import *
于 2013-07-05T00:23:27.033 回答