I am using the following project structure.
Object_Detection/
setup.py
setup.cfg
requirement.txt
object_detection/
models
__init__.py #contains from . import models
tests/
# inside tests dir
test_utils_image.py
__init__.py #empty
utils/
# inside utils dir
__init__.py #inside
utils_image_preprocess.py
utils_image.py
utils_tfrecord.py
Inside tests/test_utils_image.py I am using
from object_detection.utils import utils_image
This is throwing an error as it is not in the path.
ModuleNotFoundError: No module named 'object_detection'
Now there are couples of ways to set this to in the python module search path. One is using sys.path and the other is using PYTHONPATH inside vscode.
I tried following the below approach to make it searchable in python search module by setting up this variable inside .vscode/setting.json file
{
"python.autoComplete.extraPaths": ["./utils"],
"python.envFile": "${workspaceFolder}/.env" #is this really required, isn't this the default choice?
}
created .env file, and added a line to the empty .env file:
# Replace utils with your folder name
PYTHONPATH = utils
I also tried steps mentioned here and here but it is not working, that means, while investigating using sys.path this path is not coming up in the list
import sys
print(sys.path)
Please let me konw
- what I am doing wrong here and how can I set this path using PYTHONPATH settings?
- How to include object_detection in the search path so that going forward I can directly call anything inside object_detection (As I don't want to use sys.path in every file) (by directly calling file using python file_inside_object_detection.py (or by right-clicking in vscode), as I am aware if I will this using python -m anything_file_inside_object_detection.py then it will work)