Problem
I'm working on a Python project with the following structure:
apx-cv/
├── utils/
│ └── custom_object_functions.py
│ └── utils.py
├── models/
│ └── sample_configurations.py
└── test/
└── run_files_ee-opt.py
The utils directory contains various utility functions, and I'm trying to import them into the run_files_ee-opt.py script located in the test directory. Here's the relevant part of the run_files_ee-opt.py script:
from utils.custom_object_functions import create_hollow_room, get_arrow, create_coordinate_axes_mesh
# Rest of the code...
I'm running this script within a conda environment named apxcv. The sys.path includes the empty string '', which I understand should represent the current working directory.
However, when I try to run the script from the project root (apx-cv) using the command:
python test/run_files_ee-opt.py
I encounter the following error:
ModuleNotFoundError: No module named 'utils'
I also want to mention that earlier I have been running this script from PyCharm, and it works smoothly there. Now, I want to run it on a remote machine using terminal. When I run it using terminal, it does not work on the remote machine, or even my local machine.
The problem persists with all modules not just utils, because I wasn't able to import models either. I think I am missing something very basic, but I am not a very strong computer programmer, so I don't know much.
Things that I have tried:
- Verified
sys.path: I printedsys.pathinside the script, and it correctly includes the current working directory (''). - Absolute Import: I ensured that I'm using absolute imports (not relative imports), so
from utils.custom_object_functions import ...should be valid. - Checked Working Directory: I confirmed that the working directory is the project root (
apx-cv) when running the script. - Also checked
utils.utilsis not making an issue, as I excluded allutils-related methods. Even then, I still cannot importmodels.
The script should run without the ModuleNotFoundError since the utils module is in the correct location, and sys.path appears to be set up correctly.