我在python 3.9
这里使用的是我的文件的层次结构
- my_arithemtics
- arthimeticss_my.py
- user_imputs
- perform_calculations.py
perform_calculations.py
我想从包my_arithmetics
和模块中导入函数arthimeticss_my.py
这是代码
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))
我收到此错误
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'
__init__.py
为什么我会收到此错误,在较新版本的 python 中不需要文件
你需要在你的 python 系统路径中添加这个包在 vs code 终端上运行这些命令
PYTHONPATH=$PYTHONPATH:/<path of my_arthimetics>
export PYTHONPATH
echo $PYTHONPATH
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句