Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Package "No module named..."

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.

like image 875
whiterabbit25 Avatar asked Jul 05 '13 00:07

whiterabbit25


People also ask

How do I fix No module named error in Python?

How do i fix the no module named error in Python? We typically fix the error by adding the third party library into our development environment using the Python package installer (PIP) utility. Using PIP is relatively straightforward: Save your work and close your development environment.

Why is my module not found Python?

The ModuleNotFoundError is raised when Python cannot locate an error. The most common cause of this error is forgetting to install a module or importing a module incorrectly. If you are working with an external module, you must check to make sure you have installed it.


1 Answers

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

from .plus import *
from .minus import *
from .multiply import *
from .divide import *
like image 66
JBernardo Avatar answered Sep 19 '22 00:09

JBernardo