Blog Post How To Install External Python Modules in Universal Agent

A technical how-to on installing external Python modules by Colin Cocksedge, Director of Product Management at Stonebranch

Header Python

This is a technical how-to on installing external python modules on Stonebranch's UA (Universal Agent). Users utilizing the bundled UA python environment may require external modules not delivered with the UA python environment. In Windows, you may find that you see the following error when trying to use pip to install these modules:

“C:\Program Files\universal\python36\scripts\pip3 install requests”
pip fatal error in launcher: unable to create process using ‘”‘

This is because we install in the “C:\Program Files” location. In order to install the required python modules, you can run the following commands from a command prompt (replacing "requests" with the required module name):

'C:\Program Files\Universal\Python36\python.exe'
import pip
pip.main([‘install’,’requests’])

If you would like your script to automatically install any modules if they are not present, you can use the following example code in your script.

For example, if your Universal Task requires the “requests” module, you can use the following python code to install requests automatically if it is not already installed:

# -- Import requests, if error then install requests
try:
 import requests
except:
 try:
  from pip import main as pipmain
 except:
  from pip._internal import main as pipmain
 pipmain(
  [
    "install",
    "--trusted-host=pypi.python.org",
    "--trusted-host=pypi.org",
    "--trusted-host=files.pythonhosted.org",
    "requests",
  ]
 )
 import requests

This works for all platforms.

Did this guide help you learn something new? Feel free to share it with your colleagues.

Start Your Automation Initiative Now

Schedule a Live Demo with a Stonebranch Solution Expert

Request a Demo

Further Reading

IT Automation: Most Popular Research - TOP 10 - 2020

The Stonebranch Top 10: Most Popular IT Automation Blogs, White Papers, Videos, Success Stories and More from 2020

IT automation changes fast: WLA evolves into SOAP. Everything-as-code transforms DevOps. The scope of hybrid IT continues to expand. Stonebranch is committed to…

Hyperautomation and Workload Automation

What is Hyperautomation, and Where Does Workload Automation Fit?

The meaning of the term “hyperautomation” isn’t obvious from the name. Yet, according to Gartner, hyperautomation is one of the most important strategic…

DEMO: Automate SAP Calendar Imports Into Universal Automation Center Utilizing Universal Task

Watch this detailed product demonstration and learn how Universal Task enables you to mass import SAP calendars into UAC, saving you time and a lot of manual…

6 Ways Service Orchestration and Automation Differs from Workload Automation—and Why it Matters

Workload Automation VS Service Orchestration and Automation Platforms—and Why it Matters

Workload automation is still a vital part of IT automation. However, by adding comprehensive orchestration to the picture, enterprises can now automate across…