Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8246543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:32:22+00:00 2026-06-07T22:32:22+00:00

I Have following directory structure: src __init__.py foo1 __init__.py foo1.py foo2 __init__.py foo2.py Now

  • 0

I Have following directory structure:

src
   __init__.py
   foo1
       __init__.py
      foo1.py
   foo2
     __init__.py
     foo2.py

Now I want to import from foo2.py the module foo1.py. In foo2.py I’ve imported with from ..foo1.foo1 import * but all I get is:

Traceback (most recent call last):
  File "foo2.py", line 3, in <module>
    from ..foo1.foo1 import *
ValueError: Attempted relative import in non-package

How do I get this relative import?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T22:32:24+00:00Added an answer on June 7, 2026 at 10:32 pm

    What I see here is that the base package, in your case src has not been imported, this is a necessary condition to use relative imports.

    If you write an script that the src folder is in the sys.path, thus importable, which states:

    import src #this imports the base package
    from src.foo2.foo2 import *
    
    ...
    

    It will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following directory structure: Main.py A/ __init__.py B/ __init__.py C/ __init__.py The
I currently have the following directory structure for my code: src |-- main |
I have the following directory structure. root --src ---tests src contains the source &
I have an Eclipse project with the following directory structure: MyProj >> src/main/java >>
I have the following directory structure (root) / | \ bin resources src |
I want a Java application to have a directory structure like the following (like
I have a multi module project with the following structure: -parent -module1 -module2 -src
I have a Python project with the following directory structure: project/ project/src/ project/src/somecode.py project/src/mypackage/mymodule.py
I have a following directory structure. -webshop -controllers -webshop.php In webshop.php I want to
I have directory structure like following: analytics / / \ \ conf script src

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.