Differences Between the Remote and Local Environments
Typically, your apps that run on Beam will be using packages that you don’t have installed locally. If your Beam app uses packages that aren’t installed locally, you’ll need to ensure your Python interpreter doesn’t try to load these packages locally.Avoiding Import Errors
There are two ways to avoid import errors when using packages that aren’t installed locally.Import Packages Inline
Importing packages inline is safe because the functions will only be invoked in the remote Beam environment that has these packages installed.Use env.is_remote()
An alternative to using inline imports is to use a special check called env.is_remote()
to conditionally import packages only when inside the remote environment.
While it might be tempting to use the
env.is_remote()
flag for other logic in your app, this command should only be used for package imports.