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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:30:44+00:00 2026-06-14T12:30:44+00:00

First of all, this is very likely not a path issue. I have a

  • 0

First of all, this is very likely not a path issue.

I have a pydev project in eclipse. Here is the directory structure:

Genetic-Framework
  | Genetic-Framework
    | Genetic
      | __init__.py
      | GA.py
      | crossover.py
      | fitness.py
      | individual.py
      | mutation.py
      | population.py
      | selection.py
      | settings.py
      | visualization.py

In GA.py, I have the following line:

from Genetic import settings, selection, visualization as vis

And yes, Genetic is in sys.path. However, I get the following error:

  File "/.../Genetic-Framework/Genetic-Framework/Genetic/GA.py", line 17, in <module>
    from Genetic import settings, selection, visualization as vis
ImportError: cannot import name settings

However, when I remove settings from that line, everything else imports just fine.

Interestingly, among the first lines of settings.py is this:

from Genetic import fitness, selection, mutation, crossover, population, GA

And when I remove GA from that line, everything seems to import just fine.

Why am I getting this error? Is this some issue with circular imports? How can I fix this?

  • 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-14T12:30:46+00:00Added an answer on June 14, 2026 at 12:30 pm

    Yes, that’s an issue with circular imports.

    The problem

    The problem is that when your GA.py is run, it first tries to import settings. This means that settings.py starts getting run, and it immediately tries to import GA.

    However, GA is already in the process of loading, so GA.py doesn’t get run a second time – instead, settings just loads the GA that is already in memory (which is currently mostly empty, because it’s still executing its imports).

    Thus, things in settings that try to use things out of GA fail, because the things they’re looking for in GA haven’t been defined yet (because processing of GA.py hasn’t gotten past the imports yet).

    This makes the evaluation of settings.py raise an exception, which manifests as a failure to be imported (because an exception raised during import makes the import fail).

    The solution

    a) Avoid the situation in the first place.

    In general, you should try to avoid circular imports in the first place. They often mean that you have really odd dependency structure that will be hard to debug later.

    One way to do this is to try to find things that are needed in both modules and break them out into a separate third module that can be shared between the other two – so instead of using A.x in B, and B.y in A, you instead use C.x and C.y in both A and B.

    b) Don’t actually try to use things from circular imports until everything’s loaded.

    Another thing you can do is to defer usage of something from another module until after all of the imports have finished. In other words, don’t try to reference an imported module’s contents from top-level code, but instead place it in a class initializer or a function that you can call later on, once all of the imports have finished.

    For example, instead of this…

    import Foo
    
    class Baz:
        top_level_variable = Foo.bar
    

    you can do this:

    import Foo
    
    class Baz:
        def __init__(self):
            self.instance_variable = Foo.bar
    

    Obviously, instance properties are slightly different from class properties, but the idea is to defer actually having to look things up from other modules until after all of the modules finish executing and thus have their contents available. Also note that from Foo import bar would fail here because that tries to access the contents of Foo at the time of the import, which is what needs to be avoided.

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

Sidebar

Related Questions

First of I'm very sorry but this questions is not so so specific. All
This is very basic magento question i guess. I want to first get all
First of all thanks in advance, this has been very frustrating and I'm hoping
EDIT: solved, look below for my solution. first of all, this is my very
First and foremost, thank you all for reading this and helping, I'm very grateful.
first of all: this is not the same as this . The ModelBackend has
first of all this is my third question about web services here and i
First of all: This question is not directly programming related. However, the problem only
First of all, sorry if this might be a stupid question. I'm very new
Here are the thing, I would like to make the text 'not all likely'

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.