Impact Acquire SDK Python
Building And Running Applications Using Impact Acquire

Introduction

Note
When working with C, C++ or .NET languages this chapter will discuss how to set up makefiles, build environments and other things on the development system to get the user application compiled, linked and executed. As for Python, something like this is obviously not needed. This chapter here will explain what needs to be done to set up the Impact Acquire Python binding and which steps are necessary before an Impact Acquire Python based application can be written. For additional details on supported platforms and releases also see here: Device And Operating System Support Across Released Versions

As supporting all the various distributions and versions of Python out there with a binary interface is almost impossible, the Impact Acquire Python API needs to be compiled for a specific version of Python it shall be used with. Because of that what is shipped at the moment is source code that has been generated using SWIG which before using it requires a compilation operation.

The compilation requires a compiler that matches the version of Python that shall be used. E.g. to compile Impact Acquire for Python 3.3 on Windows systems, Visual Studio 2010 is required. Additional information about the compiler that works for a particular Python version on a particular platform can be found online. See e.g.

Note
Since Impact Acquire 3.0.1, the support for Python 2 has been dropped. It is highly recommended to migrate to Python 3.x!

When installing the Impact Acquire Python API on a target system all files needed for building the actual extension module can be found in $MVIMPACT_ACQUIRE_DIR/LanguageBindings/Python or on Windows systems in %MVIMPACT_ACQUIRE_DIR%\LanguageBindings\Python.

Note
Until version 2.35.0 the extension module can be found in $MVIMPACT_ACQUIRE_DIR/mvIMPACT_Python or on Windows systems in %MVIMPACT_ACQUIRE_DIR%\mvIMPACT_Python

Building

During the compilation process the following Python packages will be used:

Impact Acquire version required Python package
<= 2.50.1 distutils
>= 3.0.1 setuptools, build

Windows®

On Windows systems running %MVIMPACT_ACQUIRE_DIR%\LanguageBindings\Python\compileWrapperCode.bat will build and install the Python API in the site-packages sub-folder of your Python installation, provided a matching compiler could be found.

Note
The script will assume that the Python interpreter can be found in the system's Path variable. If this is not the case, please append the directory path containing the python.exe to Path variable either permanently using the System's environment variable dialog or temporarily within the command shell where the script will be called e.g.:
set Path=%Path%;C:\Python310
compileWrapperCode.bat
Depending on the version of Windows and the folder where the Impact Acquire package is installed, it might be required to start the command shell with the Run as administrator option to be able to call the compilation script.
For Impact Acquire <= 2.50.1, the distutils package coming with Python 3.6 is only capable of finding Visual Studio 2015 (i.e. MSVC 14.0). For Visual Studio 2017 or later (i.e. MSVC 14.1 or above), please make sure to compile 'Impact Acquire for Python' for Python 3.7 or greater!

Building for Anaconda distribution on Windows

Before building the Impact Acquire Python package for the Anaconda Python distribution, append the Anaconda installation path (by default: C:\Users\%userName%\Anaconda3 for Python 3.x) in the system Path variable.

Follow the instruction above to build and install the Impact Acquire Python API. The Impact Acquire package will be installed under the site-packages directory of the Anaconda path specified in the system Path variable, which is by default (for Python 3.x) C:\Users\%userName%\Anaconda3\Lib\site-packages

For Impact Acquire <= 2.50.1: in order for Anaconda Python to be able to import the Impact Acquire package, the installed package mvIMPACT-xxx-win-xxx.egg has to be split into two directories:

  • site-packages\mvIMPACT-xxx-win-xxx.egg\EGG-INFOsite-packages\mvIMPACT-xxx-win-xxx.egg-info
  • site-packages\mvIMPACT-xxx-win-xxx.egg\mvIMPACTsite-packages\mvIMPACT
Note
To make sure that users without administrator privileges are able to use the Impact Acquire Python package, Anaconda has to be installed for non-admin users as well.

Linux

On Linux systems running $MVIMPACT_ACQUIRE_DIR/LanguageBindings/Python/compileWrapperCode.sh can be used to build and install the Python API in the site-packages sub-folder of your Python installation, provided a matching compiler could be found.

Note
It is mandatory to have the C API header files for the Python version installed on the Linux system, otherwise the binaries cannot be built! Therefore please install the following package depending on your Linux distribution beforehand:
  • python3-dev on Debian and Ubuntu
  • python3-devel on Fedora
  • dev-python on Gentoo
Known exceptions are RHEL, openSUSE, Arch Linux, and NixOS. Refer to your distribution's Python packaging information for more details.

The recommended way to call the installation script is:

./compileWrapperCode.sh

It will request root privileges to install the wrapper to the site-packages directory during the process.

Note
  • Automatic installation of the required Python modules (e.g. setuptools and build) is not possible on systems that manage Python modules via the system package manager (for example Debian, Ubuntu, Arch Linux, and NixOS). If the script fails due to these missing modules, most likely you need to install the modules manually beforehand. Refer to the table above for the required modules.
  • The building process may take literally a few minutes, so please be patient!
  • The SWIG generated wrapper code source file is very large! On some embedded or 32-bit systems, gcc might have trouble digesting this file as it is known to consume a lot of memory per source line in a given translation unit. When you encounter such a situation problem please get in touch with us!

Building for Anaconda distribution on Linux

In Anaconda environment, follow the instruction above to build and install the Impact Acquire Python API. The Impact Acquire package will be installed under the site-packages directory of the Anaconda installation path, which is by default (for Python 3.x) $HOME/anaconda3/lib/python3.X/site-packages (where X is the Python minor version).

For Impact Acquire <= 2.50.1: in order for Anaconda Python to be able to import the Impact Acquire package, the installed package mvIMPACT-*.egg has to be split into two directories:

$ cd ~/anaconda3/lib/python*/site-packages
$ cp -r mvIMPACT*.egg/mvIMPACT .
$ cp -r mvIMPACT*.egg/EGG-INFO . && mv EGG-INFO "$(ls | grep mv*.egg)-info"