Tutorial: Getting started with pyVmomi on Windows : Supports vSphere 6.7

Couple of months back, I wrote an article on “How did I get started with pyVmomi on ubuntu distro?”, which was very well received.  Recently I got several requests from readers  on how to set pyVmomi on Windows platform and I thought to write this tutorial, which will take you through steps required to set pyVmomi on my Windows 10.

Step 1: Install latest python for windows.

Latest 3.x python version available is 3.6.5 on python official portal . Download the python installer as pointed out in below screenshot.

Once downloaded, while installing python, make sure to select checkbox “Add python 3.6 to PATH” as shown below.

As soon as installation is completed, I checked environment variable and I see that python 3.6 path is set properly as shown below.

I see that python is installed as expected at directory i.e. C:\Users\shitolev\AppData\Local\Programs\Python\Python36, which is default directory. I also checked python version using “python -V” command and I see correct python version is installed.

Step 2: Install pyvmomi and pyvim python modules

As I already discussed in my pyVmomi on ubuntu article, we need “pip” to install these python modules. Note that “pip” itself gets installed as part of python installation. Let us go ahead for “pyvmomi” and pyvim” modules installation by running this command
“python.exe -m pip install pyvmomi pyvim” . You can run this command from any directory of your choice.

Below is how it looks like

you can see that latest “pyvmomi” i.e. the one supports vSphere 6.7  and “pyvim” python modules got installed successfully. I also see that these modules are installed at python  directory i.e. C:\Users\shitolev\AppData\Local\Programs\Python\Python36\Lib\site-packages

Now that we are done with setting up pyVmomi on Windows, its time to run a vSphere API sample to confirm everything is working fine.

Step 3: Running vSphere API sample.

For the sake of simplicity I chose the same sample I used in my ubuntu article

[python]
# VMware vSphere Python SDK, pyvmomi
# Simple script to get vCenter server product details

from pyVim.connect import SmartConnect
import ssl

s=ssl.SSLContext(ssl.PROTOCOL_SSLv23) # For VC 6.5/6.0 s=ssl.SSLContext(ssl.PROTOCOL_TLSv1)
s.verify_mode=ssl.CERT_NONE

si= SmartConnect(host="10.192.1.2", user="Administrator@vsphere.local", pwd="VMware#123", sslContext=s)
aboutInfo=si.content.about

print ("Product Name:",aboutInfo.fullName)
print("Product Build:",aboutInfo.build)
print("Product Unique Id:",aboutInfo.instanceUuid)
print("Product Version:",aboutInfo.version)
print("Product Base OS:",aboutInfo.osType)
print("Product vendor:",aboutInfo.vendor)

[/python]

We can keep this sample file at any location of our choice and execute it as follows.

Output shows that this small pyvmomi script got executed on vSphere 6.7 successfully. How cool is that?

Note: I would like you to take a look at line #7, where I had to use “ssl.PROTOCOL_SSLv23” protocol for VC 6.7 connection. For VC 6.0 and 6.5, I used “ssl.PROTOCOL_TLSv1”.

Useful resources

1. Please take a look at tutorial on how to get hold of vSphere objects and play around. Take a look at some cool samples on VC HA

2. If you want to contribute to pyVmomi, refer pyvmomi and its samples github repo

3. Not interested in Python vSphere SDK? no problem, take a look at vSphere Java SDK and PowerCLI posts.

4. Getting started with vCenter server REST APIs using python

8 thoughts on “Tutorial: Getting started with pyVmomi on Windows : Supports vSphere 6.7

  1. Hi, Thanks for posting this article – very helpful for someone who is getting started with pyvmomi. I have read many other posts on your website as well. Wondering if you can help answer this question for me – is it possible to obtain the transport details using pyvmomi?

    vCenter – Host > Storage Devices > Device Details > Transport > SAS (for example)

    1. I am not sure if I understood your question. I think you can get upto device details using vSphere APIs. Beyond that, probably we will have to see if that particular vendor has exposed any APIs

  2. I can’t install via command:
    python.exe -m pip install pyvmomi pyvim
    Collecting pyvmomi
    Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection failed: 407 Proxy Authentication Required’))’: /simple/pyvmomi/

    it simply just can’t pass our proxy, I tried using my credentials but it doesn’t work, tried cntlm and flipper – nothing works.
    Please update your guide and write what steps are needed to resolve this issue.

  3. Hi ,

    Could you please provided the solution for proxy issue.

    Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
    after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, NewConnectio
    nError(‘<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x03DD

  4. most of the organizations block the proxy to download “pyvmomi pyvim” need a manual (download manually and install) procedure …. any one have that…..

Comments are closed.