Python package "No module named ..."

I am new to Python and am working on creating my first simple package. Here is my structure:

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

Each of the four files has a simple math function. My init file is just

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

When I try to import Math, 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 that my package should be in the correct folder; if I move any of my files outside the Math folder and start the import call by itself from the shell, it works just fine.

+4
source share
1 answer

You are using Python 3 and require relative imports within packages.

 from .plus import * from .minus import * from .multiply import * from .divide import * 
+5
source

Source: https://habr.com/ru/post/1489813/


All Articles