VMware.ImageBuilder PowerCLI module fails to load.
search cancel

VMware.ImageBuilder PowerCLI module fails to load.

book

Article ID: 312149

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article aims to document the two possible workarounds for the issue that occurs only in specific configurations.

Symptoms:
Import or invoke cmdlets from the VMware.ImageBuilder PowerCLI module fails with the following error: 
ImportError: cannot import name 'Vmodl' from 'pyVmomi'

Environment

VMware vSphere PowerCLI 13.0
VMware vSphere PowerCLI 13.1

Cause

The root cause is in a collision of Python module names. VMware.ImageBuilder carries its own copy of the pyVmomi module, and this is the one it needs. pyVmomi is also available for download through the pip Python package manager. VMware.ImageBuilder needs the one that is part of its distribution to ensure proper function.

Python prioritizes loading system modules. When their are two modules with same name, Python loads the system one. That ends up providing VMware.ImageBuilder with the wrong pyVmomi version.

Resolution

Currently there is no resolution.

Workaround:
Follow the below mentioned steps:

Workaround 1:
Configure a separate instance of Python that does not have the pyVmomi module installed. Use this instance for work with VMware.ImageBuilder.

Workaround 2:
When the PYTHONPATH environment variable is set, Python prioritizes paths specified in that variable when loading modules. We can set its value to the proper location to allow the Python VMware.ImageBuilder to  configure to work with loading the correct pyVmomi version.

Follow the below steps :
1. Find the location of PowerCLI modules.
1.1 Start a PowerShell instance.
1.2 Print the contents of the PSModulePath variable by executing 
"echo $env:PSModulePath"
1.3 Inspect the locations from step 1.2 and find the module that has VMware.ImageBuilder directory.
 
2. Prior to importing or executing VMware.ImageBuilder cmdlets, execute "$env:PYTHONPATH=<location-of-local-pyVmomi>"

Steps on how to build the <location-of-local-pyVmomi> path needed in step 2:
Format: <powercli-directory>/VMware.ImageBuilder/<version>/<dotnet-framework>/server/<python-version>
<powercli-directory>
- acquired on step 1 above.

<version> - There might be a couple of versions of VMware.ImageBuilder in the VMware.ImageBuilder directory when several PowerCLI versions are installed on the same machine. Select the desired one, which would usually be the latest one.

<dotnet-framework>
1) Mac/Linux - netcoreapp3.1
2) Windows
2.1) PowerCLI 13.1 - net472
2.2) PowerCLI 13.0 - net45

<python-version>
1) PowerCLI 13.0 - empty.
2) PowerCLI 13.1- Find the version of Python that VMware.ImageBuilder is configured to work with and substitute this field with python-<major-version><minor-version>
Example: Python version 3.7 - The field has the value python-37.