I'm on Windows 10, using Python 3.8.3. Here is my simple folder structure:
root_project_folder\
__init__.py # Empty file
project_1_folder\
__init__.py # Empty file
foo.py
project_2_folder\
__init__.py # Empty file
bar.py
Within foo.py
I have the following code:
from ..project_2_folder.bar import Test
Test.test_method()
Within bar.py
I have the following code:
class Test:
@staticmethod
def test_method():
print("Test successful")
When I run foo.py
, I receive the following error:
ImportError: attempted relative import with no known parent package
I've read a few threads about importing using relative paths. Here are the threads for reference:
Python3 relative imports failing in package
Importing files from different folder
I did not append any directories to sys.path
. I also did not modify PYTHONPATH
either, such as adding directories as an environment variable. From what I have read, I don't need to do any of that. Would I have to add something to one of the __init__.py
files?
Any help would be appreciated.