On new redhat machines 8.x. I have the following commands and the first time I run it. It's an error. Next time. It works. Time after on same machine, same error?
How do I get this to work each time? Odd as nothing else changes. Repeated it dozens and dozens of times.
CODE:
##########################################
from __future__ import print_function
import re
import requests
import os
import subprocess
import urllib3
urllib3.disable_warnings()
###########################################
def f_do_command(commandtorun):
print ("command to run:",commandtorun)
stdoutdata = subprocess.getoutput(commandtorun)
#print("stdoutdata0: ",stdoutdata.split()[0])
print("stdoutdataALL: ",stdoutdata)
return (stdoutdata)
command="yum install python3-pip -y"
f_do_command (command)
command="pip3 install orionsdk --no-cache-dir" #### no cache as without it - orionsdk import fails between uses
f_do_command (command)
try:
# Attempting to import a non-existent module
import orionsdk
except ModuleNotFoundError as e:
print(f"->ModuleNotFoundError: {e}")
import orionsdk
from orionsdk import SwisClient
print ("imported orionsdk")
RESULT:
command to run: pip3 install orionsdk --no-cache-dir
stdoutdataALL: WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Collecting orionsdk
Downloading files.pythonhosted.org/.../orionsdk-0.4.0.tar.gz
Requirement already satisfied: six in /usr/lib/python3.6/site-packages (from orionsdk)
Requirement already satisfied: requests in /usr/lib/python3.6/site-packages (from orionsdk)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests->orionsdk)
Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python3.6/site-packages (from requests->orionsdk)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python3.6/site-packages (from requests->orionsdk)
Installing collected packages: orionsdk
Running setup.py install for orionsdk: started
Running setup.py install for orionsdk: finished with status 'done'
Successfully installed orionsdk-0.4.0
->ModuleNotFoundError: No module named 'orionsdk'
Traceback (most recent call last):
File "step14_python.py", line 256, in <module>
from orionsdk import SwisClient
ModuleNotFoundError: No module named 'orionsdk'