Noob import issue

Hi there, new to Anvil and I’m following a tutorial but have hit an issue I can’t get around. Note that I’m using Python 3.

I’m importing a module into a form via:
from … import navigation (I know that Python 3 requires explicit imports)

In the form I have an init that is calling navigation.go_home()

But I keep getting the error:

AttributeError: ‘module’ object has no attribute ‘go_home’

But there is a attribute called ‘go_home’ in the module.

What am I doing wrong here?

Thanks,

Ed

Hello and welcome to the forum

happy to check your code, if you could share a clone link, so that we can find where the problem lies…

Check this for how to get the clone link and share the source code with us.

That would be fantastic:

https://anvil.works/build#clone:DJMJAUYYOB5EJZYY=7D4SZOUP3XVC2BX7ISHR7KL3

Thanks a lot.

Ed

Should mention that I changed it back to the python2 syntax of ‘import navigation’ on the version I cloned.

Change the import to :

from .. import navigation

That seems to work for me.

All new projects use python packages, and you need a relative path (which is back one from your form, hence the two dots).

The autocomplete is a big help - when you type "from " a list of visible imports is displayed for you to choose from. Most often you can select the rest of the import from there.

3 Likes

thanks, I’ve got it working now as I’ve switched to Chrome, I was using the new Edge browser which probably had something to do with it.

1 Like

I’ve hit the same problem again trying to import navigation into a different form and I can’t figure it out. Could you take another look? Check the AddMeasurementComponent, I have it with the ‘import … from navigation’ but it keeps saying ‘module’ object has no atribute ‘navigation’. I’ve tried it on both Chrome and Firefox with no change.

https://anvil.works/build#clone:DJMJAUYYOB5EJZYY=7D4SZOUP3XVC2BX7ISHR7KL3

Thanks

Actually don’t worry the exact same question was asked on a different thread.

2 Likes

hey - you’re doing the circular import thing from this tutorial - which doesn’t work

great - was just gonna point you to that thread.

1 Like