Import Client Module Error - AttributeError: ‘module’ object has no attribute - Talk Python

thanks @p.colbert :smile:

Did you manage to complete that tutorial?

I don’t think the author is going to refactor his code & re-shoot his videos. To me, he seems to be saying: “It works the way I wrote it!” and indeed it does. He pointed out that anvil.works changed how they do things just one month after he published his course…

Although that must have been a tad irksome, his course is not going to benefit anyone now. Shame that! I liked it until I didn’t.

I might buy it, if he fixes it & republishes it as a paying rather than a free course.

A thought - Anvil still supports anvil apps in the old style… i.e. without package forms… all you have to do is find someone who’s been here long enough with an app in the old style that they didn’t get round to converting.

:innocent:
https://anvil.works/build#clone:3QU4NLGDEYACNATO=JR45EFFLJZKZOIAMWTI73FD5

This way you can follow along with the video tutorials and have the same syntax.
Just don’t click :star: enable packages/upgrade to python 3…
and if you do by accident you can always revert it using the version history…

1 Like

In case it helps: you can convert any Form to be a Module Form if you want to… see my post here:

This is gently discouraged by the fact that we’ve put it behind an ‘advanced’ menu… it’s generally better that ‘every Form is a package’ to save needing to think about it. But for legacy things such as this, the conversion option is there!

2 Likes

Thanks guys. I will do that after I’ve gone through your tutorials and encultured myself into the platform. I’m ploughing through them now and I must say I am really, really impressed!

Actually, I did get the authors app from his github and ran it on anvil and it worked flawlessly, using the old ways…

When I have the skills I will do exactly as you suggest :+1:

4 Likes

To be fair, I haven’t tried. I’ve been working with Anvil for a couple of years, now, and so it didn’t seem like I was likely to learn anything from it – especially given the reported problems. That, and I have my own bread-and-butter app to work on.

That said, I am more than sympathetic. I remember needing tutorials, at many points in my career. And there are professional educators in my family, so I have a personal interest in everyone maintaining the quality of educational materials, as much as practical.

1 Like

2 posts were merged into an existing topic: How can I make modules on the client side accessible by all forms

I am following the Tutorial. At the top I put the load of the module this way:
Captura de Pantalla 2020-12-03 a la(s) 20.26.46

And in the button I calle the navigation go_home this way:

So finally it runs.

1 Like

I am following the Tutorial also in June 2021. This is what worked for me.

And in the button I call the navigation go_home this way:

Fitnessd.navigation.go_home()

The “import Fitnessd.PackageModulus.navigation” did not work for me. Not sure if that is due to continued changes in the Anvil code or if it relates to the circular import problem manifesting differently for different people??

Hope that helps somebody!

4 Likes

Thanks! I am that somebody.

1 Like

@anvil1 That worked! Thank you so much. Most frustrating 24 hours of my life lol

1 Like

Thank you so much! I spent much time trying to figure this out. It is unfortunate that some training material promoted by anvil contains this issue. On the plus side its encouraging to see that the forum contains the solution. Many thanks for sharing.

1 Like

Another thanks for this forum. I join the ranks of the frustrated, but thankfully not 24 hours, lol.

I ended up just importing the navigation within the button click (@meredydd thanks) because my app name has spaces in it so something like “import my app with spaces.navigation” does not work. Fortunately, most of my navigation is done through the menu on the left, so I only need this in a few manageable places.

Down the line, I might think about renaming my app and removing the spaces.

David

1 Like

Thank you so much I like your approach better than placing the import in the function - placing the import in the function has never been taught to me. I’ve always been shown that imports are always to be placed first up above everything else being code from my understanding - but I do understand why @meredydd mentioned placing it in the function itself. Thank you again and Thank you All for contributing to this Forum. as my journey continues learning Anvil, sometimes I wonder if I should go back to Django :thinking:
I also do wonder if these two ways of implementing the task work which one is the True Pythonic and correct way? hmm “loaded question perhaps”

Back to Django? That is a thing I never wondered :slight_smile:.

1 Like

so your saying that since you have been using Avil you have never looked back(Django), that’s promising thank you :+1:

That’s true. And the pep8 style guide agrees with this statement.
That said, there are examples of imports within functions in the cpython source code e.g.

datetime.py - due to circular import

functools.py - for performance reasons

2 Likes

Thank you @stucork, because of your involvement like this and all the other contributors to this forum it’s just amazing and truly appreciative. Thank you for that piece of information it really helps me as I continue to grasp Python & Anvil thank you again.

1 Like

@support1: I too had problems with this circulair import thing which deviates from the TalkPython course when I started with Anvil. However the solution of Meredydd works fine, so I now import my navigation module local in the function. I still use the set-up of the course for my own apps, because this structure for navigation and caching is good. My problem with Django was that I had to study a lot of blogs and manuals to get anything done that was more complex than showing just a simple form. I’m very glad with the Anvil documentation which is very compact and to the point. And if I have question and post it on the forum it’s usually answered within half an hour, even at midnight :slight_smile: !

1 Like

Thank you, I see we share similar thoughts when it comes to the Django even though htmlx is calling me I really feel anvil is solid and can take me a long way hopefully, thanks again :+1:t5:

hey everyone, I’m really very new to Python and Anvil.
I’ve got a problem in writing my code related to signing in in a simple webApp which is:

self.change_sign_in_text()
    self.content_panel.add_component(Home())
  def change_sign_in_text(self):
   user = anvil.user.get_user() 

AttributeError: module ‘anvil’ has no attribute ‘user’

Well. I don’t even know how to… :frowning: