Installing Packages
To import a third-party package into your app’s Server Modules, you need to install it into that app’s server environment. Packages in Anvil are installed on a per-app basis, meaning that you can add only the necessary packages for each app.
Adding packages
Packages can be added to your app’s server environment under Python packages, by entering a package name (as it appears in PyPI) in the ‘Package name’ box. For each package, a version can be specified, or left blank to use the latest version.
After adding packages to your app, you can interact with them in the Server Console.
Anvil’s package management uses pip, so packages can be installed from PyPI, a GitHub repository, or a URL using pip’s Requirements File Format. To install packages from somewhere other than PyPI, see Advanced Options.
Build output
Once you add custom packages to the list, Anvil will install those packages to create a new server environment.
Possible errors
Anvil presents the output from pip’s install process directly. The two most common causes of build failures happen when a requested package could not be found, and when there is a conflict in dependency versions.
Package does not exist
ERROR: Could not find a version that satisfies the requirement `bad-package` (from versions: none)
ERROR: No matching distribution found for `bad-package`
Error: Build failedThis typically happens due to a typo. Double-check that the package you have requested is spelled correctly, and that the requested version (if any) is correct.
Conflicting dependencies
ERROR: Cannot install pymongo==4.1.0 and pymongo==4.1.1 because these package versions have conflicting dependencies.
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/topics/dependency-resolution/#dealing-with-dependency-conflicts
Error: Build failedThis happens when the dependencies you have requested have incompatible requirements. For help resolving this, visit pip’s dependency conflict management page.
Checking for Vulnerabilities
Once a server environment has been built, Anvil will use pip-audit to check the installed dependencies of that environment for vulnerabilities. The output of this can be seen below the Build Output section.
If security vulnerabilities are detected, a button will appear, linking a report of which packages are affected.
Advanced options
Editing your app’s requirements.txt directly
You can edit your app’s requirements.txt file directly, by clicking the link at the lower left of the Package section.
This will open up a text editor in which you can type your package list directly, just as you would into a requirements.txt file. This allows you to specify more nuance in your version dependencies, such as using the <= operator.
Running bash scripts
You can add pre-install or post-install bash scripts under Advanced settings…, in the Pre-install script and Post-install script sections.
Open the ‘Advanced settings…’ section to access the install scripts configuration
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.