I am trying to access a function in package1 from inside package 2
project |- __init__.py |- package1 |-__init__.py |-module1.py |- package2 |-__init__.py |-module2.py
package1/__init __.py
from .module1 import my_function # I have also tried the following: # from module1 import my_function # from module1 import * # import module1 # and also leaving this file empty
package2/module2.py
from ..package1 import my_function # I have also already tried the following: # from ..package1 import my_function # import sys # sys.path.append('.') # import package1
https://stackoverflow.com/questions/66838039/importerror-attempted-relative-import-with-no-known-parent-package March 28, 2021 at 11:03AM
没有评论:
发表评论