From a2eb1aff119590cb683c991ed6c5e3c740b81cee Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 11:34:07 -0700 Subject: [PATCH] Use relative import for Coder class in main.py # Context: USER: $ python3 ./aider/main.py Traceback (most recent call last): File "/Users/gauthier/Projects/aider/./aider/main.py", line 5, in from aider.coder import Coder ModuleNotFoundError: No module named 'aider' ASSISTANT: It seems like there is an issue with importing the `Coder` class from the `aider` package. To fix this, you can try adding the current directory to the `sys.path`. Here's the change you need to make in the `aider/main.py` file: ```python aider/main.py <<<<<<< ORIGINAL import os import sys import argparse from dotenv import load_dotenv from aider.coder import Coder ======= import os import sys sys.path.append(os.path.dirname(os.path ^C KeyboardInterrupt USER: i would rather not do that. is there a different way to do the import so that it works both when the aider package is pip installed and also when its being run from the repo checkout? ASSISTANT: Yes, you can use a relative import instead of an absolute import. This will work both when the package is installed via pip and when it's being run from the repo checkout. Here's the change you need to make in the `aider/main.py` file: ```python aider/main.py <<<<<<< ORIGINAL from dotenv import load_dotenv from aider.coder import Coder ======= from dotenv import load_dotenv from .coder import Coder >>>>>>> UPDATED ``` This change replaces the absolute import with a relative import, which should resolve the `ModuleNotFoundError`. --- aider/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aider/main.py b/aider/main.py index fba5e5afb..b5e36359e 100644 --- a/aider/main.py +++ b/aider/main.py @@ -2,8 +2,7 @@ import os import sys import argparse from dotenv import load_dotenv -from aider.coder import Coder - +from .coder import Coder def main(): load_dotenv()