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.
Anvil provides multiple options for server environments. These can be selected from the drop-down menu under ‘Python version’, after navigating to ‘Python versions’ in your app’s Settings.
- Python 3.10 (Beta) allows you to install custom packages into your app’s server environment.
- Basic Python includes only the Standard library, and is the only option on the Free Plan.
- Full Python 3 and Full Python 2 are the standard Anvil server environments with many packages already installed.
There are currently 4 Base Environments available. Choose a Base Environment that best suits your needs, to minimise the number of custom packages you will have to install yourself. For example, if you need the
pandas package, we recommend starting from the Standard Base Environment, which already includes this package. If you also need
tensorflow, choose the Machine Learning Base Environment.
This is a lightweight environment, containing only the necessary packages to run Anvil server code (such as, for example, ws4py).
This image contains everything from the Minimal environment, along with the following packages and all their dependencies:
This image contains everything from the Standard environment, along with the following packages and all their dependencies:
This image contains everything from the Data Science environment, along with the following packages and all their dependencies:
Packages can be added to your app’s server environment by entering a package name (as it appears in PyPI) in the left-hand box underneath the ‘Package’ section of the Python version settings. For each package, a version can be specified in the right-hand box, or left blank to use the latest version.
To install packages from somewhere other than PyPI, see Advanced Options.
Once you add custom packages to the list, Anvil will install those packages to create a new server environment.
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 failed
This 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.
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 failed
This happens when the dependencies you have requested have incompatible requirements. For help resolving this, visit pip’s dependency conflict management page.
Once a server environment has been built, Anvil will use safety 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.
Editing your app’s
Anvil’s package mamagement uses pip, so packages can be installed from PyPI, a GitHub repository, or a URL using pip’s Requirements File Format. Your app’s
requirements.txt file can also be edited 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
Do you still have questions?
Our Community Forum is full of helpful information and Anvil experts.