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.

Mr_and_Mrs_D
  • 32,208
  • 39
  • 178
  • 361
whiterabbit25
  • 267
  • 3
  • 10

1 Answers1

10

You are using Python 3 and it requires relative imports inside packages.

from .plus import *
from .minus import *
from .multiply import *
from .divide import *
JBernardo
  • 32,262
  • 10
  • 90
  • 115