我有这样的文件结构
/home/ec2-user/wep-rs/WEPR/weprs/api/voucher.py
/home/ec2-user/wep-rs/WEPR/weprs/api/scrappers/quotes/quotes.py
i want to access voucher.py from quotes.py
我试过了
import sys
sys.path.append("..")# ValueError: attempted relative import beyond top-level package
from .. .. import api # ValueError: attempted relative import beyond top-level package
sys.path.append("/home/ec2-user/wep-rs/WEPR/weprs/api/")
from api.voucher import Voucher
error i am getting is
ModuleNotFoundError: No module named 'api'
不过,你走的路是对的。。你知道吗
应该是:
在我向您展示的示例中,
from voucher import Voucher
尝试从/home/ec2-user/wep-rs/WEPR/weprs/api/voucher.py
导入Voucher
类。你知道吗否则,以您的方式,您将尝试访问
/home/ec2-user/wep-rs/WEPR/weprs/api/api/voucher.py
。另外,请记住必须有一个__初始.py__目录中的文件。你知道吗
相关问题 更多 >
编程相关推荐