I am using python 3.9
here is the hierachy of my files
- my_arithemtics
- arthimeticss_my.py
- user_imputs
- perform_calculations.py
I want import functions in perform_calculations.py
from package my_arithmetics
and module arthimeticss_my.py
here is the code
arthimeticss_my.py
def my_add(a, b):
return (a b)
def my_subtract(a, b):
return (a-b)
perform_calculations.py
from my_arthimetics.arthimeticss_my import *
a = float(input(" Enter the first number: "))
b = float(input( "Enter the 2nd number: "))
calc = input("Enter s for subtract and a for addition: ").lower()
if calc == "s":
print(my_subtract(a, b))
if calc == "a":
print(my_add(a, b))
I am getting this error
Traceback (most recent call last):
File "/home/django_dev/Documents/testing_python/user_inputs/perform_calculations.py", line 1, in <module>
from my_arthimetics.arthimeticss_my import my_add, my_subtract
ModuleNotFoundError: No module named 'my_arthimetics'
Why am i getting this error
there is no need of __init__.py
file in newer versions of python
CodePudding user response:
You need to add this package in your python system path run these commands on vs code terminal
PYTHONPATH=$PYTHONPATH:/<path of my_arthimetics>
export PYTHONPATH
echo $PYTHONPATH