You have mutual top-level imports, which is almost always a bad idea.

If you really must have mutual imports in Python, the way to do it is to import them within a function:

# In b.py:
def cause_a_to_do_something():
    import a
    a.do_something()

Now a.py can safely do import b without causing problems.

(At first glance it might appear that cause_a_to_do_something() would be hugely inefficient because it does an import every time you call it, but in fact the import work only gets done the first time. The second and subsequent times you import a module, it's a quick operation.)

Answer from RichieHindle on Stack Overflow
Discussions

package - Python error: AttributeError: 'module' object has no attribute - Stack Overflow
I'm totally new to Python and I know this question was asked many times, but unfortunately it seems that my situation is a bit different... I have created a package (or so I think). The catalog tre... More on stackoverflow.com
🌐 stackoverflow.com
"Module ... has no attribute ..."
The thing with imports is they are relative to the "working directory". And that directory is decided by the IDE (vscode). It could be a directory that you don't expect, and it could be loading something else instead of what you want. So do 3 things to check what goes wrong. 1 - Add code to the start of converters.py to make sure it gets loaded, and print its path print("converters is loaded") print(__file__) def lbstokg(...): ... ... 2 - Add code to the start of main, to figure out the current working directory, and list files there. import os print(os.getcwd()) print(os.listdir()) 3 - add code in main to print converter's file. import converters print(converters.__file__) this should help find any issues, if you can't figure out what's wrong, show us the output of these additions. More on reddit.com
🌐 r/learnpython
4
3
March 26, 2023
Import Client Module Error - AttributeError: ‘module’ object has no attribute - Talk Python
Hello everyon I was wondering if someone could help me. With the new folder structure I cannot seem to import the module into the sub forms. My structure is as follows App -> Main Form -> Sub Form 1| Sub Form2 | Subform X | navigation module I have tried to import the module in the sub form ... More on anvil.works
🌐 anvil.works
1
1
January 2, 2020
How to fix AttributeError: module has no attribute
Body I just installed anaconda, and jupyter notebook. And was testing its features. Then, I found a problem while importing the module, and I haven't found a solution yet. I tried making a simp... More on github.com
🌐 github.com
2
2
🌐
Containersolutions
containersolutions.github.io › runbooks › posts › python › module-has-no-attribute
Module has no attribute – Runbooks - GitHub Pages
Given the above code a call to foo.bar() within main.py would result in an error about the module ‘foo’ not having the attribute ‘bar’. This is because we have only made the module accessible and not it’s class foo.
🌐
Net Informations
net-informations.com › python › err › attr.htm
Module object has no attribute error: Python
This means that you got the error when the "module" does not contain the method you are calling. But it is evident that the method is there, which leads to believe that may be the method was added by you in the source code after you had already imported the file (module).
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-module-has-no-attribute
AttributeError: module 'X' has no attribute 'Y' in Python | bobbyhadz
April 8, 2024 - Having an incorrect import statement. (use print(dir(your_module)) to see what you imported) Trying to access an attribute that doesn't exist on the module.
🌐
Reddit
reddit.com › r/learnpython › "module ... has no attribute ..."
r/learnpython on Reddit: "Module ... has no attribute ..."
March 26, 2023 -

I'm writing python in vscode. I have 2 py files (main and converters).

Converters:

def lbstokg(weight):
return weight*0.45

def kgtolbs(weight):
return weight / 0.45

Main:

import converters
print(converters.lbstokg(10))

Error when running: AttributeError: module 'converters' has no attribute 'lbstokg'

Why? It's in the same folder, it knows that the module is there because it's in the dropdown list after typing converters.. The code works in pycharm but doesn't in vscode.

Find elsewhere
🌐
Hinty
hinty.io › rivashchenko › module-has-no-attribute-python-is-easy
Module has no attribute [Python is easy] - hinty.io
AttributeError: module 'modules' has no attribute 'module_2' At first sight, it seems strange why the third call raise this error because we imported 'modules' and the second call works correctly. But if you want to use import modules and call a method in such way you need to add import these modules in __init__.py . · P. s. : Do not use cross-import in modules. It can also cause this error and even worse. #python · RELATED POSTS · What does * mean in python ·
🌐
Codingdeeply
codingdeeply.com › home › troubleshooting: python module has no attribute – tips and solutions
Troubleshooting: Python Module Has No Attribute - Tips and Solutions
February 23, 2024 - A: There are several steps you can take to troubleshoot and fix this error, such as checking if the attribute exists, importing the attribute correctly, or checking for naming conflicts.
🌐
Quora
quora.com › Why-does-the-Module-object-has-no-attributeerror-occur-in-Python-2
Why does the 'Module object has no attribute'error occur in Python 2? - Quora
Since func is not a method defined ... no attribute 'X'" in Python 2 means you tried to access attribute X on a module object but that attribute does not exist on that module at runtime....
🌐
YouTube
youtube.com › watch
How to Resolve Module Has No Attribute - Python Error Messages - YouTube
In this tutorial I will be showing you how to MANAGE THE "MODULE HAS NO ATTRIBUTE" ERROR MESSAGE using Python. This is a step-by-step detailed tutorial made ...
Published   December 21, 2019
🌐
Medium
medium.com › @kasata › understanding-and-fixing-pythons-attributeerror-module-object-has-no-attribute-x-cb25b49311ab
Understanding and Fixing Python’s AttributeError: 'module' object has no attribute 'X' | by KASATA - TechVoyager | Medium
May 25, 2024 - Several common issues can lead to the AttributeError: 'module' object has no attribute 'X': 1. Typographical Errors One of the most common reasons is a typo in the attribute name.
🌐
JanBask Training
janbasktraining.com › community › python-python › attributeerror-module-object-has-no-attribute
AttributeError: \'module\' object has no attribute | JanBask Training Community
April 20, 2021 - If you really must have mutual imports in Python, the way to do it is to import them within a function: def cause_a_to_do_something(): import a a.do_something() Note : Getting AttributeError: 'module' object has no attribute because there is no attribute with the name you called, for that Object.
🌐
Medium
kasata.medium.com › understanding-and-fixing-the-python-attributeerror-module-object-has-no-attribute-x-a634971754df
Understanding and fixing the Python AttributeError: ‘module’ object has no attribute ‘X’ | by KASATA - TechVoyager | Medium
March 24, 2024 - So, ensure that the attribute exists ... object has no attribute ‘X’` error in Python is caused by trying to access a non-existent attribute from a Python module....
🌐
Itsourcecode
itsourcecode.com › home › attributeerror module has no attribute
Attributeerror module has no attribute [SOLVED]
April 3, 2023 - But before that let us know first What this error means. “Attributeerror module has no attribute” is a python error message that indicates you are trying to access an attribute or method that doesn’t exist in the given module. ... It refers to a situation in which two or more files in a project depend on each other, forming a loop of dependencies.
🌐
Ask Ubuntu
askubuntu.com › questions › 572630 › attributeerror-module-object-has-no-attribute-python
14.04 - AttributeError: 'module' object has no attribute python - Ask Ubuntu
January 11, 2015 - Traceback (most recent call last): File "get-pip.py", line 28, in <module> import tempfile File "/usr/lib/python2.7/tempfile.py", line 35, in <module> from random import Random as _Random File "/usr/lib/python2.7/random.py", line 49, in <module> import hashlib as _hashlib File "/usr/lib/python2.7/hashlib.py", line 138, in <module> _hashlib.openssl_md_meth_names) AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
🌐
Reddit
reddit.com › r/learnpython › [deleted by user]
"Module has no attribute" issue : r/learnpython
November 30, 2023 - Subreddit for posting questions and asking for general advice about all topics related to learning python. ... Importing a package does not make the modules within it available directly.
🌐
Unix Tutorial
unixtutorial.org › attributeerror-module-has-no-attribute-python
AttributeError: module has no attribute in Python | Unix Tutorial
March 20, 2020 - Because my own example code was saved in the csv.py file, I was making it import itself instead of the standard (global) Python 3 csv module. The fix is simple: rename your file to something else and it will no longer be importing itself.