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 8892475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:00:31+00:00 2026-06-14T23:00:31+00:00

I am having a problem importing from a specific module, but not importing from

  • 0

I am having a problem importing from a specific module, but not importing from modules in general. My project structure:

project-folder
  aaa-folder
    __init__.py
    a.py
  bbb-folder
    __init__.py
    b.py
  ccc-folder
    __init__.py
    c.py

All the init.py files are blank. The project-folder is in my sys.path.

module b:

from aaa.a import a_method
from ccc.c import c_method

def b_method(): print 'bye'
print 'hi'

module c:

from aaa.a import a_method
from bbb.b import b_method

def c_method(): print 'bye'
print 'hi'

module a:

from bbb.b import b_method
from ccc.c import c_method

def a_method(): print 'bye'
print 'hi'

I can import every method from the python shell. Module b and c both run from the command line and simply return ‘hi’. When I run module a, I get ImportError: No module named b

Where might I find clues to my problem?

  • 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-14T23:00:33+00:00Added an answer on June 14, 2026 at 11:00 pm

    As mentioned a few times in the comments, you are designing you project to use circular imports:

    Circular imports are fine where both modules use the “import ”
    form of import. They fail when the 2nd module wants to grab a name out
    of the first (“from module import name”) and the import is at the top
    level. That’s because names in the 1st are not yet available, because
    the first module is busy importing the 2nd.

    If you place a print statement at the very top of each of those modules, you will see what is happening…

    Example a,b,c: print "inside aaa" # bbb, ccc

    When you execute module a, you will get this:

    $ python aaa/a.py 
    inside aaa
    inside bbb
    inside aaa
    Traceback (most recent call last):
      File "aaa/a.py", line 2, in <module>
        from bbb.b import b_method
      File "/Users/user/Desktop/project/bbb/b.py", line 2, in <module>
        from aaa.a import a_method
      File "/Users/user/Desktop/project/aaa/a.py", line 2, in <module>
        from bbb.b import b_method
    ImportError: cannot import name b_method
    

    a.py goes to import b.py, but b needs a, so it goes back to that module, where it sees the rest of the bbb import. Well b was only partial loaded at this point, so b_method is not yet defined. So you get a crash.

    What you should do is avoid having your modules import each other in circles. There should be a set of common modules for which others all import the shared functionality. But as stated in the python faq, it can be worked around by only importing the module namespace (import bbb).

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

Sidebar

Related Questions

I'm having trouble importing definitions from modules in Coq. I'm new to Coq, but
I am having a problem with importing and using the dnspython or easyzone modules
Im having problem in importing hotmail contacts from hotmail in php it simple give
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
I am having some difficulty with importing data from a .csv file. I am
I am having a problem with the example from this article . The article
i want to call a binary program from within my module. i am having
I am having problems importing Python's random module using Eclipse. It creates a red
I am having problems importing models between my apps in my current django project.
I'm importing this project from another file, and everything else goes well except for

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.