I have a site that I’ve been working on, and today it stopped working with the following error:
ImportError: No module named Pages
This is from the following import:
from ..Pages.Sponsors import Sponsors
When I used autocomplete to recreate the import, it produced the exact same import which also failed.
The problem ended up being that I’d removed the boilerplate content from the package itself. Packages are generated with the following code:
import anvil.google.auth, anvil.google.drive
from anvil.google.drive import app_files
import anvil.users
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables
import anvil.server
# This is a package.
# You can define variables and functions here, and use them from any form. For example, in a top-level form:
#
# from . import Package1
#
# Package1.say_hello()
#
def say_hello():
print("Hello, world")
I’d assumed that boilerplate wasn’t necessary, and deleted it. Then the imports stopped working.
To get the imports working again, I had to restore the boilerplate and save and publish a new version.
I don’t know if this indicates a bug somewhere, but it was painful enough to debug that I thought I’d let you all know about it.