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

Back to Blog Overview
Analyst Report EMA Radar WLA Q4 2019 Value Leader

Further Reading

Read the blog: Automation Trends 2024: Top Takeaways from the Annual Global State of IT Automation Report

Automation Trends 2024: Top Takeaways from the Annual Global State of IT Automation Report

The results are in! IT Ops, DevOps, DataOps, CloudOps, PlatformOps, and ITSM pros worldwide share their thoughts on automation and orchestration in the 2024…

Header Card Analyst Report: 2022 Global State of IT Automation Report

Stonebranch 2024 Global State of IT Automation Report

The results are in! New research reveals 2024's IT automation and orchestration benchmarks for IT Ops, DevOps, CloudOps, and DataOps teams.

Read the blog post: 6 Top Trends in Infrastructure and Operations (I&O) for 2024

6 Top Trends in Infrastructure and Operations (I&O) for 2024

2024's top trends in infrastructure and operations (I&O), including genAI, IT orchestration, MLOps, and self-service automation.

Watch the webinar now! Orchestration, Observability, and Control Over the Hybrid Data Pipeline

Orchestration, Observability, and Control Over the Hybrid Data Pipeline

Hybrid data pipelines involve multiple schedulers and real-time data issues — see how an orchestration layer can enhance observability and control.