Why do I receive an AttributeError even though import, spelling and file location is correct?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








5















  1. I am using PyCharm


  2. All files are in the directory 'venv'



    • venv

    • NoteFunction.py

    • NoteMainApp.py

    • ...


I split up my code in five separate files. One 'main' file, gathering all other files and creating eventually the GUI. The prefix for the files is 'Note' followed an appropriate description.



My problem now is the import of 'NoteTopMenu' into the main file 'NoteMainApp'.
The code is:



import NoteStatusbar as SB
import NoteTopMenu as TM
import NoteWidgets as NW
import tkinter as tk


class MainApp(tk.Frame):

def __init__(self, parent):

tk.Frame.__init__(self,parent)
super().__init__(parent)
self.topbar = TM.TopMenu(parent)
self.widget = NW.FrontFrames(parent)
self.statusbar = SB.StatusBar(parent)


root = tk.Tk()
MainApp(root).pack(side="top", fill="both")

root.mainloop()


I receive the error message:



Traceback (most recent call last):
File "C:/Users/PycharmProjects/MindNotez/NoteMainApp.py", line 2, in <module>
import NoteTopMenu as TM
File "C:UsersPycharmProjectsMindNotezNoteTopMenu.py", line 2, in <module>
import NoteMainApp as Main
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 29, in <module>
MainApp(root).pack(side="top", fill="both")
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 13, in __init__
self.topbar = TM.TopMenu(parent)


AttributeError: module 'NoteTopMenu' has no attribute 'TopMenu'



The code in NoteTopMenu is:



import NoteMainApp as Main
import NoteWidgets as NW
import tkinter as tk


class TopMenu(NW.FrontFrames):
"""Class creating the top menu bar."""
def __init__(self, master):
super().__init__(master)
# *******Top-Navigation Bar (tnb)**********
tnb = tk.Menu(master)
Main.root.config(menu=tnb)
....


If I comment the NoteTopMenu out in the main file, the code runs without a problem. I checked my spelling but PyCharm also offers me code-completion. Therefore, PyCharm finds the file, the module, my class and other module are imported without an issue. Do you know why the file/module is not being found or fails to be imported?



Full code is here on GitHub: MindNotez



Thank you very much for your help!










share|improve this question






















  • Incidentally, congratulations on a really clearly expressed question with the complete required information.

    – Martin Bonner
    Nov 15 '18 at 10:41

















5















  1. I am using PyCharm


  2. All files are in the directory 'venv'



    • venv

    • NoteFunction.py

    • NoteMainApp.py

    • ...


I split up my code in five separate files. One 'main' file, gathering all other files and creating eventually the GUI. The prefix for the files is 'Note' followed an appropriate description.



My problem now is the import of 'NoteTopMenu' into the main file 'NoteMainApp'.
The code is:



import NoteStatusbar as SB
import NoteTopMenu as TM
import NoteWidgets as NW
import tkinter as tk


class MainApp(tk.Frame):

def __init__(self, parent):

tk.Frame.__init__(self,parent)
super().__init__(parent)
self.topbar = TM.TopMenu(parent)
self.widget = NW.FrontFrames(parent)
self.statusbar = SB.StatusBar(parent)


root = tk.Tk()
MainApp(root).pack(side="top", fill="both")

root.mainloop()


I receive the error message:



Traceback (most recent call last):
File "C:/Users/PycharmProjects/MindNotez/NoteMainApp.py", line 2, in <module>
import NoteTopMenu as TM
File "C:UsersPycharmProjectsMindNotezNoteTopMenu.py", line 2, in <module>
import NoteMainApp as Main
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 29, in <module>
MainApp(root).pack(side="top", fill="both")
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 13, in __init__
self.topbar = TM.TopMenu(parent)


AttributeError: module 'NoteTopMenu' has no attribute 'TopMenu'



The code in NoteTopMenu is:



import NoteMainApp as Main
import NoteWidgets as NW
import tkinter as tk


class TopMenu(NW.FrontFrames):
"""Class creating the top menu bar."""
def __init__(self, master):
super().__init__(master)
# *******Top-Navigation Bar (tnb)**********
tnb = tk.Menu(master)
Main.root.config(menu=tnb)
....


If I comment the NoteTopMenu out in the main file, the code runs without a problem. I checked my spelling but PyCharm also offers me code-completion. Therefore, PyCharm finds the file, the module, my class and other module are imported without an issue. Do you know why the file/module is not being found or fails to be imported?



Full code is here on GitHub: MindNotez



Thank you very much for your help!










share|improve this question






















  • Incidentally, congratulations on a really clearly expressed question with the complete required information.

    – Martin Bonner
    Nov 15 '18 at 10:41













5












5








5








  1. I am using PyCharm


  2. All files are in the directory 'venv'



    • venv

    • NoteFunction.py

    • NoteMainApp.py

    • ...


I split up my code in five separate files. One 'main' file, gathering all other files and creating eventually the GUI. The prefix for the files is 'Note' followed an appropriate description.



My problem now is the import of 'NoteTopMenu' into the main file 'NoteMainApp'.
The code is:



import NoteStatusbar as SB
import NoteTopMenu as TM
import NoteWidgets as NW
import tkinter as tk


class MainApp(tk.Frame):

def __init__(self, parent):

tk.Frame.__init__(self,parent)
super().__init__(parent)
self.topbar = TM.TopMenu(parent)
self.widget = NW.FrontFrames(parent)
self.statusbar = SB.StatusBar(parent)


root = tk.Tk()
MainApp(root).pack(side="top", fill="both")

root.mainloop()


I receive the error message:



Traceback (most recent call last):
File "C:/Users/PycharmProjects/MindNotez/NoteMainApp.py", line 2, in <module>
import NoteTopMenu as TM
File "C:UsersPycharmProjectsMindNotezNoteTopMenu.py", line 2, in <module>
import NoteMainApp as Main
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 29, in <module>
MainApp(root).pack(side="top", fill="both")
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 13, in __init__
self.topbar = TM.TopMenu(parent)


AttributeError: module 'NoteTopMenu' has no attribute 'TopMenu'



The code in NoteTopMenu is:



import NoteMainApp as Main
import NoteWidgets as NW
import tkinter as tk


class TopMenu(NW.FrontFrames):
"""Class creating the top menu bar."""
def __init__(self, master):
super().__init__(master)
# *******Top-Navigation Bar (tnb)**********
tnb = tk.Menu(master)
Main.root.config(menu=tnb)
....


If I comment the NoteTopMenu out in the main file, the code runs without a problem. I checked my spelling but PyCharm also offers me code-completion. Therefore, PyCharm finds the file, the module, my class and other module are imported without an issue. Do you know why the file/module is not being found or fails to be imported?



Full code is here on GitHub: MindNotez



Thank you very much for your help!










share|improve this question














  1. I am using PyCharm


  2. All files are in the directory 'venv'



    • venv

    • NoteFunction.py

    • NoteMainApp.py

    • ...


I split up my code in five separate files. One 'main' file, gathering all other files and creating eventually the GUI. The prefix for the files is 'Note' followed an appropriate description.



My problem now is the import of 'NoteTopMenu' into the main file 'NoteMainApp'.
The code is:



import NoteStatusbar as SB
import NoteTopMenu as TM
import NoteWidgets as NW
import tkinter as tk


class MainApp(tk.Frame):

def __init__(self, parent):

tk.Frame.__init__(self,parent)
super().__init__(parent)
self.topbar = TM.TopMenu(parent)
self.widget = NW.FrontFrames(parent)
self.statusbar = SB.StatusBar(parent)


root = tk.Tk()
MainApp(root).pack(side="top", fill="both")

root.mainloop()


I receive the error message:



Traceback (most recent call last):
File "C:/Users/PycharmProjects/MindNotez/NoteMainApp.py", line 2, in <module>
import NoteTopMenu as TM
File "C:UsersPycharmProjectsMindNotezNoteTopMenu.py", line 2, in <module>
import NoteMainApp as Main
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 29, in <module>
MainApp(root).pack(side="top", fill="both")
File "C:UsersPycharmProjectsMindNotezNoteMainApp.py", line 13, in __init__
self.topbar = TM.TopMenu(parent)


AttributeError: module 'NoteTopMenu' has no attribute 'TopMenu'



The code in NoteTopMenu is:



import NoteMainApp as Main
import NoteWidgets as NW
import tkinter as tk


class TopMenu(NW.FrontFrames):
"""Class creating the top menu bar."""
def __init__(self, master):
super().__init__(master)
# *******Top-Navigation Bar (tnb)**********
tnb = tk.Menu(master)
Main.root.config(menu=tnb)
....


If I comment the NoteTopMenu out in the main file, the code runs without a problem. I checked my spelling but PyCharm also offers me code-completion. Therefore, PyCharm finds the file, the module, my class and other module are imported without an issue. Do you know why the file/module is not being found or fails to be imported?



Full code is here on GitHub: MindNotez



Thank you very much for your help!







python python-3.x attributeerror






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 9:03









Alex_PAlex_P

3291415




3291415












  • Incidentally, congratulations on a really clearly expressed question with the complete required information.

    – Martin Bonner
    Nov 15 '18 at 10:41

















  • Incidentally, congratulations on a really clearly expressed question with the complete required information.

    – Martin Bonner
    Nov 15 '18 at 10:41
















Incidentally, congratulations on a really clearly expressed question with the complete required information.

– Martin Bonner
Nov 15 '18 at 10:41





Incidentally, congratulations on a really clearly expressed question with the complete required information.

– Martin Bonner
Nov 15 '18 at 10:41












1 Answer
1






active

oldest

votes


















6














You invoke NoteMainApp.py which imports NoteTopMenu.py which imports NoteMainApp.py which does not go on to re-import NoteTopMenu.py (because the import has already started). The import of NoteMainApp.py then goes on to parse the rest of the file. At this point the module NoteTopMenu is defined, but it doesn't have any attributes (because you haven't got round to defining them yet) ... hence the error.



I suggest that NoteTopMenu.py should not import NoteMainApp.py (and if there are any bits which both files need, they should be moved into another file that both can import)






share|improve this answer























  • Thank you very much for the answer. I will try it out and get back to everybody.

    – Alex_P
    Nov 15 '18 at 9:19






  • 1





    This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

    – Rob Bricheno
    Nov 15 '18 at 9:20












  • Thank you very much and everybody. Your answer explained the issue I had.

    – Alex_P
    Nov 15 '18 at 9:54











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315744%2fwhy-do-i-receive-an-attributeerror-even-though-import-spelling-and-file-locatio%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














You invoke NoteMainApp.py which imports NoteTopMenu.py which imports NoteMainApp.py which does not go on to re-import NoteTopMenu.py (because the import has already started). The import of NoteMainApp.py then goes on to parse the rest of the file. At this point the module NoteTopMenu is defined, but it doesn't have any attributes (because you haven't got round to defining them yet) ... hence the error.



I suggest that NoteTopMenu.py should not import NoteMainApp.py (and if there are any bits which both files need, they should be moved into another file that both can import)






share|improve this answer























  • Thank you very much for the answer. I will try it out and get back to everybody.

    – Alex_P
    Nov 15 '18 at 9:19






  • 1





    This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

    – Rob Bricheno
    Nov 15 '18 at 9:20












  • Thank you very much and everybody. Your answer explained the issue I had.

    – Alex_P
    Nov 15 '18 at 9:54















6














You invoke NoteMainApp.py which imports NoteTopMenu.py which imports NoteMainApp.py which does not go on to re-import NoteTopMenu.py (because the import has already started). The import of NoteMainApp.py then goes on to parse the rest of the file. At this point the module NoteTopMenu is defined, but it doesn't have any attributes (because you haven't got round to defining them yet) ... hence the error.



I suggest that NoteTopMenu.py should not import NoteMainApp.py (and if there are any bits which both files need, they should be moved into another file that both can import)






share|improve this answer























  • Thank you very much for the answer. I will try it out and get back to everybody.

    – Alex_P
    Nov 15 '18 at 9:19






  • 1





    This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

    – Rob Bricheno
    Nov 15 '18 at 9:20












  • Thank you very much and everybody. Your answer explained the issue I had.

    – Alex_P
    Nov 15 '18 at 9:54













6












6








6







You invoke NoteMainApp.py which imports NoteTopMenu.py which imports NoteMainApp.py which does not go on to re-import NoteTopMenu.py (because the import has already started). The import of NoteMainApp.py then goes on to parse the rest of the file. At this point the module NoteTopMenu is defined, but it doesn't have any attributes (because you haven't got round to defining them yet) ... hence the error.



I suggest that NoteTopMenu.py should not import NoteMainApp.py (and if there are any bits which both files need, they should be moved into another file that both can import)






share|improve this answer













You invoke NoteMainApp.py which imports NoteTopMenu.py which imports NoteMainApp.py which does not go on to re-import NoteTopMenu.py (because the import has already started). The import of NoteMainApp.py then goes on to parse the rest of the file. At this point the module NoteTopMenu is defined, but it doesn't have any attributes (because you haven't got round to defining them yet) ... hence the error.



I suggest that NoteTopMenu.py should not import NoteMainApp.py (and if there are any bits which both files need, they should be moved into another file that both can import)







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 9:10









Martin BonnerMartin Bonner

23.8k33267




23.8k33267












  • Thank you very much for the answer. I will try it out and get back to everybody.

    – Alex_P
    Nov 15 '18 at 9:19






  • 1





    This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

    – Rob Bricheno
    Nov 15 '18 at 9:20












  • Thank you very much and everybody. Your answer explained the issue I had.

    – Alex_P
    Nov 15 '18 at 9:54

















  • Thank you very much for the answer. I will try it out and get back to everybody.

    – Alex_P
    Nov 15 '18 at 9:19






  • 1





    This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

    – Rob Bricheno
    Nov 15 '18 at 9:20












  • Thank you very much and everybody. Your answer explained the issue I had.

    – Alex_P
    Nov 15 '18 at 9:54
















Thank you very much for the answer. I will try it out and get back to everybody.

– Alex_P
Nov 15 '18 at 9:19





Thank you very much for the answer. I will try it out and get back to everybody.

– Alex_P
Nov 15 '18 at 9:19




1




1





This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

– Rob Bricheno
Nov 15 '18 at 9:20






This is known as a circular dependency or circular import. It's usually a bad idea in python as it tends to cause problems like the one shown here. If you ever feel the need to do this, it indicates a design problem in the way you've organised your code. There's a nice blog post about it here stackabuse.com/python-circular-imports

– Rob Bricheno
Nov 15 '18 at 9:20














Thank you very much and everybody. Your answer explained the issue I had.

– Alex_P
Nov 15 '18 at 9:54





Thank you very much and everybody. Your answer explained the issue I had.

– Alex_P
Nov 15 '18 at 9:54



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315744%2fwhy-do-i-receive-an-attributeerror-even-though-import-spelling-and-file-locatio%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20