Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempted relative import with no known parent package #144

Open
kaizhuanren opened this issue Jul 15, 2024 · 1 comment
Open

Attempted relative import with no known parent package #144

kaizhuanren opened this issue Jul 15, 2024 · 1 comment

Comments

@kaizhuanren
Copy link

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

@yinanhe
Copy link
Member

yinanhe commented Jul 16, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants