VMware vSphere Automation SDK for Python

Hi,

Anyone can suggest on below will help. I am getting error when tried to install VMware vSphere Automation SDK for Python on centos7

Below is my server details

Doc i am following is

https://github.com/vmware/vsphere-automation-sdk-python#installing-required-python-packages

cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

python --version
Python 2.7.5

yum install -y python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

Even below fails

pip install --upgrade pyvmomi

Traceback (most recent call last):
File “/usr/bin/pip”, line 9, in
load_entry_point(‘pip==21.0.1’, ‘console_scripts’, ‘pip’)()
File “/usr/lib/python2.7/site-packages/pkg_resources.py”, line 378, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File “/usr/lib/python2.7/site-packages/pkg_resources.py”, line 2566, in load_entry_point
return ep.load()
File “/usr/lib/python2.7/site-packages/pkg_resources.py”, line 2260, in load
entry = import(self.module_name, globals(),globals(), [‘name’])
File “/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py”, line 60
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax

Also tried below :

mkdir ansible-vmware-project
cd ansible-vmware-project/
git clone https://github.com/vmware/vsphere-automation-sdk-python.git
python3 -m venv venv
source venv/bin/activate
cd vsphere-automation-sdk-python

pip install --upgrade pip setuptools
Collecting pip
Downloading https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5MB)
100% |████████████████████████████████| 1.5MB 990kB/s
Collecting setuptools
Downloading https://files.pythonhosted.org/packages/15/0e/255e3d57965f318973e417d5b7034223f1223de500d91b945ddfaef42a37/setuptools-53.0.0-py3-none-any.whl (784kB)
100% |████████████████████████████████| 788kB 2.0MB/s
Installing collected packages: pip, setuptools
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Found existing installation: setuptools 36.5.0
Uninstalling setuptools-36.5.0:
Successfully uninstalled setuptools-36.5.0
Successfully installed pip-21.0.1 setuptools-53.0.0

pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-python.git
Collecting git+https://github.com/vmware/vsphere-automation-sdk-python.git
Cloning https://github.com/vmware/vsphere-automation-sdk-python.git to /tmp/pip-req-build-3ciikd1i
Running command git clone -q https://github.com/vmware/vsphere-automation-sdk-python.git /tmp/pip-req-build-3ciikd1i
Processing //tmp/pip-req-build-3ciikd1i/lib/vapi-runtime/vapi_runtime-2.19.0-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/vapi-client-bindings/vapi_client_bindings-3.5.0-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/vapi-common-client/vapi_common_client-2.19.0-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/vmc-client-bindings/vmc_client_bindings-1.33.0-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/nsx-python-sdk/nsx_python_sdk-3.0.2.0.0.16837625-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/nsx-policy-python-sdk/nsx_policy_python_sdk-3.0.2.0.0.16837625-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/nsx-vmc-policy-python-sdk/nsx_vmc_policy_python_sdk-3.0.2.0.0.16837625-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/nsx-vmc-aws-integration-python-sdk/nsx_vmc_aws_integration_python_sdk-3.0.2.0.0.16837625-py2.py3-none-any.whl
Processing //tmp/pip-req-build-3ciikd1i/lib/vmc-draas-client-bindings/vmc_draas_client_bindings-1.17.0-py2.py3-none-any.whl
Collecting lxml>=4.3.0
Downloading lxml-4.6.2-cp36-cp36m-manylinux1_x86_64.whl (5.5 MB)

████████████████████████████████| 5.5 MB 16.7 MB/s
Collecting pyVmomi>=6.7
Downloading pyvmomi-7.0.1.tar.gz (584 kB)
████████████████████████████████| 584 kB 93.1 MB/s
Collecting suds-jurko
Downloading suds-jurko-0.6.zip (255 kB)
████████████████████████████████| 255 kB 81.6 MB/s
Requirement already satisfied: setuptools in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from vapi-client-bindings@ file://localhost//tmp/pip-req-build-3ciikd1i/lib/vapi-client-bindings/vapi_client_bindings-3.5.0-py2.py3-none-any.whl->vSphere-Automation-SDK==1.47.0) (53.0.0)
Collecting pyOpenSSL>=18.0.0
Downloading pyOpenSSL-20.0.1-py2.py3-none-any.whl (54 kB)
████████████████████████████████| 54 kB 7.2 MB/s
Collecting six>=1.12
Downloading six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting requests>=2.21.0
Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
████████████████████████████████| 61 kB 20.6 MB/s
Collecting cryptography>=3.2
Downloading cryptography-3.4.4-cp36-abi3-manylinux2014_x86_64.whl (3.2 MB)
████████████████████████████████| 3.2 MB 85.7 MB/s
Collecting cffi>=1.12
Downloading cffi-1.14.5-cp36-cp36m-manylinux1_x86_64.whl (401 kB)
████████████████████████████████| 401 kB 77.6 MB/s
Collecting pycparser
Downloading pycparser-2.20-py2.py3-none-any.whl (112 kB)
████████████████████████████████| 112 kB 105.6 MB/s
Collecting certifi>=2017.4.17
Downloading certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
████████████████████████████████| 147 kB 95.7 MB/s
Collecting chardet<5,>=3.0.2
Downloading chardet-4.0.0-py2.py3-none-any.whl (178 kB)
████████████████████████████████| 178 kB 88.0 MB/s
Collecting idna<3,>=2.5
Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
████████████████████████████████| 58 kB 15.8 MB/s
Collecting urllib3<1.27,>=1.21.1
Downloading urllib3-1.26.3-py2.py3-none-any.whl (137 kB)
████████████████████████████████| 137 kB 100.6 MB/s
Using legacy ‘setup.py install’ for vSphere-Automation-SDK, since package ‘wheel’ is not installed.
Using legacy ‘setup.py install’ for pyVmomi, since package ‘wheel’ is not installed.
Using legacy ‘setup.py install’ for suds-jurko, since package ‘wheel’ is not installed.
Installing collected packages: pycparser, cffi, urllib3, six, idna, cryptography, chardet, certifi, requests, pyOpenSSL, vapi-runtime, vapi-common-client, vmc-draas-client-bindings, vmc-client-bindings, vapi-client-bindings, suds-jurko, pyVmomi, nsx-vmc-policy-python-sdk, nsx-vmc-aws-integration-python-sdk, nsx-python-sdk, nsx-policy-python-sdk, lxml, vSphere-Automation-SDK
Running setup.py install for suds-jurko … done
Running setup.py install for pyVmomi … done
Running setup.py install for vSphere-Automation-SDK … done
Successfully installed certifi-2020.12.5 cffi-1.14.5 chardet-4.0.0 cryptography-3.4.4 idna-2.10 lxml-4.6.2 nsx-policy-python-sdk-3.0.2.0.0.16837625 nsx-python-sdk-3.0.2.0.0.16837625 nsx-vmc-aws-integration-python-sdk-3.0.2.0.0.16837625 nsx-vmc-policy-python-sdk-3.0.2.0.0.16837625 pyOpenSSL-20.0.1 pyVmomi-7.0.1 pycparser-2.20 requests-2.25.1 six-1.15.0 suds-jurko-0.6 urllib3-1.26.3 vSphere-Automation-SDK-1.47.0 vapi-client-bindings-3.5.0 vapi-common-client-2.19.0 vapi-runtime-2.19.0 vmc-client-bindings-1.33.0 vmc-draas-client-bindings-1.17.0

export PYTHONPATH=${PWD}:$PYTHONPATH

ansible-galaxy collection install community.vmware
Process install dependency map
Starting collection install process
Installing ‘community.vmware:1.7.0’ to ‘/root/.ansible/collections/ansible_collections/community/vmware’

ansible-inventory --list -i DC-inv-ALL-vmware.yml
[WARNING]: * Failed to parse /root/ansible-vmware-project/vsphere-automation-sdk-python/playbooks/DC-inv-ALL-vmware.yml with auto plugin: Please install “PyVmomi” Python module
as this is required for VMware Guest dynamic inventory plugin.
[WARNING]: * Failed to parse /root/ansible-vmware-project/vsphere-automation-sdk-python/playbooks/DC-inv-ALL-vmware.yml with yaml plugin: Plugin configuration YAML file, not
YAML inventory
[WARNING]: * Failed to parse /root/ansible-vmware-project/vsphere-automation-sdk-python/playbooks/DC-inv-ALL-vmware.yml with ini plugin: Invalid host pattern ‘plugin:’ supplied,
ending in ‘:’ is not allowed, this character is reserved to provide a port.
[WARNING]: Unable to parse /root/ansible-vmware-project/vsphere-automation-sdk-python/playbooks/DC-inv-ALL-vmware.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
“_meta”: {
“hostvars”: {}
},
“all”: {
“children”: [
“ungrouped”
]
}
}

BTW

pip install pyvmomi
Requirement already satisfied: pyvmomi in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (7.0.1)
Requirement already satisfied: requests>=2.3.0 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from pyvmomi) (2.25.1)
Requirement already satisfied: six>=1.7.3 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from pyvmomi) (1.15.0)
Requirement already satisfied: certifi>=2017.4.17 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from requests>=2.3.0->pyvmomi) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from requests>=2.3.0->pyvmomi) (1.26.3)
Requirement already satisfied: chardet<5,>=3.0.2 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from requests>=2.3.0->pyvmomi) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in /root/ansible-vmware-project/venv/lib/python3.6/site-packages (from requests>=2.3.0->pyvmomi) (2.10)

ansible --version
ansible 2.9.17
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/root/.ansible/plugins/modules’, u’/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

pip show pyvmomi
Name: pyvmomi
Version: 7.0.1
Summary: VMware vSphere Python SDK
Home-page: https://github.com/vmware/pyvmomi
Author: VMware, Inc.
Author-email: jhu@vmware.com
License: License :: OSI Approved :: Apache Software License
Location: /root/ansible-vmware-project/venv/lib/python3.6/site-packages
Requires: requests, six
Required-by: vSphere-Automation-SDK

https://github.com/ansible/ansible/issues/64144

Ansible is using Python binary from /usr/lib/python3.6/site-packages/ansible
whereas Pyvmomi is installed here - /usr/local/lib/python3.6/site-packages

In my case :

ansible python module location = /usr/lib/python2.7/site-packages/ansible

Pyvmomi –

/root/ansible-vmware-project/venv/lib/python3.6/site-packages

Can you please check the environment ??

Not sure about the above … tried few rsync … no luck… @Abhijit any comment Please

Clearly you’ve mixed everything up. Multiple python3, python2, pips, and individual venvs, even running as root.

Perhaps start with a fresh OS, and just a python3 virtualenv?

Thanks for the reply… Yes i already tested with Ubuntu20.04 & it works fine… the issue i have is my actual prod ansible server still runs as CentOS7 which natively supports Pytrhon2x … so trying these test on a test box running centos7

i did many things …lost track … anyone wants to know Please check the freenode channel

removed ansible & installed with pip

/usr/local/bin/ansible --version
ansible 2.10.5
config file = None
configured module search path = [‘/root/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.7.9 (default, Feb 11 2021, 15:13:23) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

seems ok now