[BETA-Designer] ModuleNotFoundError: No module named '_anvil_designer'

The first line of both DataGridJson and ValidatingTextBox imports from ._anvil_designer:
image
image

But one works and the other doesn’t:

Hi @stefano.menci,

This is because the custom component form is a module, rather than a package (which makes it very old - anything created recently is a package).

Screenshot 2023-10-04 at 12.42.43

We intend to put a better error message on it, but the designer doesn’t support live interaction with module forms. You can convert your custom component form to a package by clicking the “…” next to it in the App Browser. The change should be minimal - you’ll just need to add an extra . to the start of any relative imports in your form code.

2 Likes

Ouch!!

I have counted 34 apps that depend from the custom component HeaderWithLogin. There may be more apps that I missed.

I started following your advice, that is changing this:

import CommonFunctionsClient
from UserConfigPage import UserConfigPage

into this:

from .. import CommonFunctionsClient
from ..UserConfigPage import UserConfigPage

And it did work.

But then I remembered about the importgeddon I always have when executing the apps in PyCharm, then running tests, then using apps as dependencies, then running apps as stand alone apps, and I followed these guidelines (at paragraph “Relative vs absolute imports”): always use the app/dependency name when importing.

So I changed it into this:

from HeaderWithLogin import CommonFunctionsClient
from HeaderWithLogin.UserConfigPage import UserConfigPage

I tested with two apps and everything seems to be working well with their dependencies set to development.

Tomorrow I will crawl through all the other apps, ready to answer the phone. It will be a long day.

… or is there a better approach?

Two reasons not to worry too much about this:

  1. This isn’t breaking any code! Your apps and components still run fine. The only thing that happens is that Custom Components that are module forms are static in the new designer (like all custom components in the classic designer!) rather than ‘live’. So, no rush.

  2. If you’re changing a form from module to package, the only code whose imports you should need to change is the code inside the form that you just switched from module to package. Everything else (including code that imports objects from your form, which is pretty rare) should work unmodified.

2 Likes

Update: If you use a module form as a Custom Component, we’ve now taken away the red border. You’ll just see a warning in Designer Output. So your old custom components should now work exactly as before!

3 Likes

I have switched to package both forms and modules.

Does that mean that the only imports that need to be updated are the ones inside the custom component app, and all dependent app will not need any changes?

Does that mean that the only imports that need to be updated are the ones inside the custom component app, and all dependent app will not need any changes?

Yup!

1 Like