4 weeks ago
When creating Python UDF's, you may depend on external libraries to accomplish some tasks. When these libraries are not installed by default, the UDF's will return an error stating that the module is not found. This article will describe how you solve this problem.
If the Python library you are trying to import is not installed by default, you will receive an error message like this:
[Code: 0, SQL State: 22002] VM error: F-UDF-CL-LIB-1125: F-UDF-CL-SL-PYTHON-1000: F-UDF-CL-SL-PYTHON-1017: ExaUDFError: F-UDF-CL-SL-PYTHON-1122: Exception while parsing UDF
<UDF name>:1 <module>
ImportError: No module named <module name>
(Session: 1690055142405898240)
Exasol's script languages are built using a set of default packages that are commonly used in Python applications. However, these are by no means exhaustive, and it is not possible to prepare for all possibilities. In regular Python environments, you can use pip install to add additional packages, but this command is not available within the Exasol database. You can use the below script to see exactly which packages are available for you to use.
--/
CREATE OR REPLACE PYTHON3 SCALAR SCRIPT "GET_AVAILABLE_PYTHON_MODULES" () EMITS ("res" VARCHAR(4096) UTF8) AS
import pkgutil as pkgutil
def run(ctx):
for module_name in pkgutil.iter_modules():
ctx.emit(module_name[1])
/
Note: If using Python 2, just replace the PYTHON3 with PYTHON in the script definition.
To solve this problem, you can create a new Script Language Container. Before creating the container, you will add the requested packages to the flavors/<flavor>/flavor_customization/packages directory. The basic steps to create a Container look like this:
Note: You can use the exaslct command to automatically upload the built container into BucketFS and to generate the ALTER SESSION statement needed by running the following command:
./exaslct upload --flavor-path=flavors/<flavor-name> --database-host <hostname-or-ip> --bucketfs-port <port> \
--bucketfs-username w --bucketfs-password <password> --bucketfs-name <bucketfs-name> \
--bucket-name <bucket-name> --path-in-bucket <path/in/bucket>
You can find more in-depth instructions in the Readme of the Github Repository
We're happy to get your experiences and feedback on this article below!
Then it's time to become part of a unique family! Discover helpful tips and support other Community members with your knowledge.
Sign In