Import from root / client code / absolute path

Newbie question here (probably more python-related than specific to anvil), but is there a straightforward way to import from the root directory rather than a relative path?

For example, suppose I have a config module client_code/config.py, which contains some config values that I import into many many other forms and modules. Say I import it into form_1 with from .. import config. If I move form_1 to a Pages package, then I have to change the import to from ... import config.

What I want is a universal import statement that will work regardless of the directory it is called from. Something like from root import config.

Is there an elegant way to do this?

Ah, I figured it out. I guess it’s just from package_name import config where package_name is the name you specify in settings > dependencies > package name.

1 Like

However, I have one follow-up request and one follow-up question.

Request: Would it be possible to make autocomplete (in Anvil’s IDE) work in this case?

Question: How can I make an external IDE (VScode) recognize the package_name as the client_code module?

1 Like

This could help you with the import problem: Setting up an environment for testing modules locally

I haven’t created a new app in a while, so I don’t know if it is still current, but you can give it a try.

1 Like