Sometimes it makes sense to make use of Python packages that are not part of the Lexocad Python distribution. To make sure the user installs the required packages OpenLexocad provides a helper funktion:
installPythonPackage(<aPackageName>)
This function will install the package using Python’s pip module. It is also possible to specify a specific version:
SomePackage==1.0.4 # specific version SomePackage>=1.0.4 # minimum version
Before installing a package it makes sense to check whether it has been already installed. Here is an example where presence of the numpy package is checked. It importing fails the script will install the package:
# Using an external Python Package in Lexocad import OpenLxApp as lx try: import numpy as np except ImportError: lx.installPythonPackage('numpy') import numpy as np a = np.array( [20,30,40,50] ) print (type(a))