Attempted relative import with no known parent package
When I run this demo.ipynb, I encounter the following import error. Theoretically, Python should be able to successfully import from the current directory using ..utils.easydict. Can you explain why this is happening? ImportError Traceback (most recent call last) Cell In[1], line 8 4 import cv2 6 import torch ----> 8 from config import (Config, 9 eval_dict_leaf) 11 from utils import (retrieve_text, 12 _frame_from_video, 13 setup_internvideo2)
File InternVideo-main/InternVideo2/multi_modality/demo/config.py:17 13 from importlib import import_module 15 import yaml ---> 17 from ..utils.easydict import EasyDict 19 all = ["Config", "pretty_text"] 22 BASE_KEY = "base"
ImportError: attempted relative import with no known parent package
Perhaps the following can be helpful to you:
Method1: Create a Package: The most straightforward solution is to structure your project as a package:
InternVideo-main/InternVideo2/multi_modality/
├── __init__.py
├── utils/
│ └── easydict.py
|...
__init__.py: This empty file signals to Python that the my_project directory is a package.
Method2: Absolute Imports: If you don't want to create a package structure, use absolute imports:
from InternVideo-main.InternVideo2.multi_modality.utils.easydict import EasyDict
This assumes your my_project directory is on your Python path (either in your PYTHONPATH environment variable or in a location Python searches by default).
@yinanhe I am still running into this issue, it keeps saying "ImportError: attempted relative import with no known parent package" even though I put blank __init__.py files in every folder.
@qingy1337 I checked the code again, and maybe it just need to make sure that the easydict package has been installed, without using relative paths.
https://github.com/OpenGVLab/InternVideo/blob/1c57368fd1942da9e8a24f3404222cffa92cf5b9/InternVideo2/multi_modality/utils/config.py#L17
@yinanhe I solved it by running this code from the multi_modality folder, not multi_modality/demo:
import numpy as np
import os
import io
import cv2
import torch
from demo.config import (Config,
eval_dict_leaf)
from demo.utils import (retrieve_text,
_frame_from_video,
setup_internvideo2)
Now the problem is that flash_attn is taking forever (1+ hrs) to install....
@yinanhe I solved it by running this code from the
multi_modalityfolder, notmulti_modality/demo:import numpy as np import os import io import cv2 import torch from demo.config import (Config, eval_dict_leaf) from demo.utils import (retrieve_text, _frame_from_video, setup_internvideo2)Now the problem is that
flash_attnis taking forever (1+ hrs) to install....
Yes, Installing flash_attn is time consuming, but not a necessary library without training
@yinanhe Sorry, I'm still a bit confused, would you mind creating a fork of this repo with a working demo.ipynb? Thanks!
EDIT: Nevermind, I got it working!!