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.
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.
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.
You are using Python 3 and it requires relative imports inside packages.
from .plus import *
from .minus import *
from .multiply import *
from .divide import *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With