Running Anvil locally - ._anvil_designer could not be resolved

What I’m trying to do:
Use the app designed on Anvil cloud and run it locally on PC (Windows 10 in this case, but should be general inc macs). Using VSC.
What I’ve tried and what’s not working:
Followed https://github.com/anvil-works/anvil-runtime/blob/master/doc/getting-started.md.
Cloned my published GitHub repo to local.

$ python -m venv .venv # local environment to install packages to
$ pip install anvil-app-server

Latter does clear most of the import errors but still left with error on running:
Import "._anvil_designer" could not be resolved

This is a bit odd because I don’t want to run the Designer (have done that bit on cloud account), just run the generated app code in the anvil-app-server installed!

There’s a different doc inside the git - https://github.com/anvil-works/anvil-runtime/blob/master/doc/getting-started.md and this implies needing to install the JVM and Postgresql but I don’t get to that stage yet and it doesn’t seem to include the ._anvil_designer. Where would I even get the designer if needed (hopefully not)?

Welcome to the forum! :wave:

Can you provide a little more detail about what step you were at when you encountered this error? Providing more of the error traceback could also be helpful, if there is more information.

Also, something puzzling about what you wrote is how you say you followed the ‘getting-started.md’ and then later you say “There’s a different doc…” but then you link to the same ‘getting-started.md’ doc. Maybe you meant to refer to the README.md one of those times?

What version are you using, by the way?

To explain, the “designer” being referred to is not the cloud IDE but rather the way the output of the IDE is referred to in the Python code. (For example)

1 Like

Thanks for heads up Tim, and conf I’m on the right track - and that the designer ref is part of all local intalls and not just those wanting the full IDE.

Apologies, the first link should have been the initial readme.md at base of git repo: GitHub - anvil-works/anvil-runtime: The runtime engine for hosting Anvil web apps

This is where is says to use $ pip install anvil-app-server followed by a ref to the second link (about the JVM and Postgresql).

You app looks interesting - have you run this locally?

I figured it was just a case of needing to install the extra package - full error from VSC is:

Exception has occurred: ImportError
attempted relative import with no known parent package
  File "M:\ZZ\Repos-WD-Samples\tickbox-anvil-test-feedback\client_code\frmFeedback\__init__.py", line 1, in <module>
    from ._anvil_designer import frmFeedbackTemplate
ImportError: attempted relative import with no known parent package

This is triggered from the first line in the source code (where VSC intellisense shows the "Import "._anvil_designer" could not be resolved"):

from ._anvil_designer import frmFeedbackTemplate
from anvil import *
import anvil.server
import anvil.tables as tables
import anvil.tables.query as q
from anvil.tables import app_tables

class frmFeedback(frmFeedbackTemplate):
  def __init__(self, **properties):
    # Set Form properties and Data Bindings.
    self.init_components(**properties)
    ... etc

Looks like the “parent package” is the oddly named “._anvil_designer” (.underscore prefix presumably marking it as internal) which is not available and/or not providing the child frmFeedbackTemplate which is my renaming of the Anvil intro tutorials app Form (my MS Access hangover but useful “frm” prefixes). The “class frmFeedback(frmFeedbackTemplate)” is included in code above and is the only 2 refs in the whole codebase I can find. Perhaps this is where it’s gone wrong - the Template is not included after the form being renamed?

Oh, Anvil is current version from yesterday, anvil.yaml shows:

runtime_options: {version: 2, client_version: '3', server_version: python3-sandbox,
  server_spec: null}

Python is 3.11, pip 23.2.1, latter could be upgraded to 23.3.1. I just wiped the .venv after that upgrade to 23.3.1 and recreated with new pip install anvil-app-server dependencies but same error.

Ah, I see from Anvil Settings server it uses python 3.7 and 3.10 is in beta, so maybe 3.11 is pushing the boat out too far - will work out how to install that alongside others (conda, windows store, base etc) and update here.

python 3.7 is legacy now (Python Release Python 3.7.17 | Python.org) so no direct installers without patching older ones, and miniconda won’t install it at all - could faff about but as Anvil has 3.10 in beta and that is already installed (via conda) have created new venv from that, updated pip, run the $ pip install anvil-app-server and under 3.10.10… still same error.

Any advice welcome!

For Windows, install Python, Coretto (Java runtime), and Git first.

You mentioned: ‘this implies needing to install the JVM and Postgresql but I don’t get to that stage yet’. You need the Java runtime before continuing the rest of the process. I’ve used Coretto versions 11 and later successfully with anvil-app-server on Windows.

Next, create and activate your python environment:

python -m venv anvildir
cd anvildir
Scripts\activate

Then install the anvil_app_server (optionally with a version identifier), and any python libraries imported in your app:

pip install anvil_app_server==1.7.3
pip install bcrypt pandas

Then clone your git repository:

git clone ssh://name%40site.com@anvil.works:2222/ASDFAS12ASDFASDF.git App_Name

Then run anvil-app-server:

anvil-app-server --app <insert_your_cloned_APP_NAME_directory_here> --origin http://192.169.1.100:3031 (insert the IP address of the machine runnig your app, and optionally the port on which you want to run your app (3030 is default))

The first time you run the your app in the Python environment folder you created above, anvil-app-server will download the required Java server and Postgres database software.

2 Likes

Be aware there are some Anvil features which don’t work on Windows (PDF generation from Anvil forms and automated https termination using the Traefik version packaged in Anvil on Linux, for example).

Note: I have successfully run anvil-app-server using Ubuntu on WSL in Windows 11.

3 Likes

Thanks Nick!

I installed AWS Coretto 11 from Amazon Corretto 11 Installation Instructions for Windows 10 or Later - Amazon Corretto and ran this and indeed it installed the Anvil App Server JAR to package directory (in my venv):

(.venv) M:\ZZ\T710-Repos-WD-Samples\tickbox-anvil-test-feedback>anvil-app-server --app tickbox-anvil-test-feedback --origin http://127.0.0.1:3031 
Downloading Anvil App Server JAR to package directory
100% of 336.9 MiB |#######...#######| Elapsed Time: 0:05:42 Time:  0:05:42
Downloaded Anvil App Server JAR to package directory
Error: opening registry key 'Software\JavaSoft\Java Runtime Environment'
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.

So now I just need the JRE running on windows… prev ditched that as it asks for updates constantly but am ok to bring it back - am inclined to use the official MS SDK at Download the Microsoft Build of OpenJDK | Microsoft Learn but could use the Oracle source instead.

Question is, what version should I use for this Anvil?

Yay!! It runs on Windows (even without WSL - which I do have and is handy, but still a hassle).

I used the latest MS OpenJDK - v21. Reboot required or still never found the JRE/JVM. Set the HOME_PATH during installation - perhaps this was why the AWS Coretto never kicked in - so removed that installation and Anvil still works, so not needed if OpenJDK instead.

Now the JAR installed into venv (had to re-do it all as hyphens not allowed in app name dir, need to use those underscores, and simple rename went pear shaped), it got on with the DB migrations and bingo!

(.venvanvil) M:\ZZ\Repos-WD-Samples>anvil-app-server --app tickbox_anvil_test_feedback --origin http://127.0.0.1:3031
Found Anvil App Server JAR in package directory
Found 7 migration(s) for (base runtime) DB.
Executing Anvil migrations...
Database currently at "2023-03-31-inline-media-storage"
Database is already up to date.
[TRACE anvil.app-server.run] Invalidating; new version 1
[INFO  anvil.core.server] HTTP Server running on port 3031
[INFO  anvil.app-server.run] App URL:  http://127.0.0.1:3031
[INFO  anvil.app-server.dispatch] Launching built-in downlink...
[INFO  anvil.app-server.run] SMTP Server running on port 25
Warning: PDF Rendering not supported on Windows. Renderer not initialised
Connecting to ws://localhost:3031/_/downlink
Anvil websocket open
[INFO  anvil.executors.downlink] Downlink client connected with spec {:runtime "python3-full", :session_id "KoBPkZkAsUBc5hrEvvtZ"}
Downlink authenticated OK

Anvil running locally

So will get back to testing out Anvil as a data management solution - can now tell clients it’s runnable on PCs, VMs, Docker containers etc (even Windows!), so not completely proprietary cloud only (ie real open source). Love it! Appreciate your caveats about some functionality including the PDF gen it warns about - perfectly understandable and those things are usually licenced (and paid for) separately. Another good reason for the cloud system. Generally, there’s no need to do all this hassle to run locally when it’s provided hosted, just good to know (and some ents will insist as per the price plans).

Many thanks for your help Nick, Tim et al, keep up the good works!

2 Likes

Glad to hear you got things running :slight_smile:

1 Like