0

I have the following Python project structure and running my script from the root directory using python -m image_batch_processor.main works. Also testing with the unittest module from the root using discovery works fine

.
├── README.md
├── image_batch_processor
│   ├── __init__.py
│   ├── argument_parser.py
│   ├── data_collection
│   │   ├── __init__.py
│   │   └── image_file_finder.py
│   ├── image_batch_processor.py
│   ├── image_processing
│   │   ├── image_modification.py
│   │   ├── preview_label_creator.py
│   │   └── utilities
│   └── main.py
└── tests

However within every file I get an "import could not be resolved" from the LSP - as for example for imports within main.py:

from image_batch_processor.argument_parser import argument_parser
from image_batch_processor.data_collection.image_file_finder import ImageFileFinder
from image_batch_processor.image_batch_processor import ImageBatchProcessor

But also imports of installed modules like numpy or cv2 show the same error even though they show up in pip list

It's not a major issue since the code is working, but I'd like to get rid of the error messages.

I looked it up and sometimes the right interpreter had to be chosen in the virtual environment, however I'm using pyenv and my environment is active and the correct interpreter is chosen.

maosi100
  • 25
  • 5
  • Ok it was a pyright pyenv issue. Solved by following this post: https://stackoverflow.com/a/66559305/20175565 – maosi100 Apr 13 '23 at 09:14

1 Answers1

1

Looks like the env is not working properly or selected acordingly. Try creating a venv for this project. Your project should look like this:

.
├── README.md
├── image_batch_processor
│   ├── __init__.py
│   ├── argument_parser.py
│   ├── data_collection
│   │   ├── __init__.py
│   │   └── image_file_finder.py
│   ├── image_batch_processor.py
│   ├── image_processing
│   │   ├── image_modification.py
│   │   ├── preview_label_creator.py
│   │   └── utilities
│   └── main.py
├── tests
└── venv
apiuser
  • 21
  • 5
  • I'm using pyenv with my virtualenvironment activated: /Users/user/.pyenv/versions/image_batch_processor/bin/python – maosi100 Apr 13 '23 at 09:03