0

I am new to unix & cloud not from IT background and not sure how to install Java manually on cloud. I am trying to install Java on streamlit to be able to use Pyspark.

I have tried below code but not sure how to install using downloaded .rpm file with python.

App_link

Github_link

import streamlit as st
import pandas as pd

import os
import sys
import wget
# import tarfile
import platform

1. Download Java

# for linux from: https://crunchify.com/where-is-java-installed-on-my-mac-osx-system/
f = wget.download("https://download.oracle.com/otn-pub/java/jdk/11.0.2+9/f51449fcd52f4d52b93a989c5c56ed3c/jdk-11.0.2_linux-x64_bin.rpm")

st.write(" Java Downloaded")

Java Downloaded

2. Cross check Platform

st.write("Checking platform: ",platform.system())

Checking platform: Linux

3. Checking Directories & files

st.write("Current Directory: ",os.getcwd())
st.write("Directory list: ",os.listdir())

Current Directory: /mount/src/os_explore

Directory list:

[ 0:"requirements.txt" 1:"app.py" 2:"README.md" 3:".git" 4:"jdk-11.0.2_linux-x64_bin.rpm" 5:"packages.txt" 6:".streamlit" ]

4. Installing using .rpm file

# from: https://stackoverflow.com/questions/49484772/install-rpm-or-msi-file-through-python-script
import rpm
import subprocess
package_path = '/mount/src/os_explore/jdk-11.0.2_linux-x64_bin.rpm'
# command = ['rpm', '-Ivh', package_path]
command = ['rpm', '-ivh', package_path]
p = subprocess.Popen(command)
p.wait()
if p.returncode == 0:
    print("OK")
else:
    print("Something went wrong")

Getting Errors from here onwards

enter image description here

Error in text:

ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.

2023-09-30 05:04:01.256 Uncaught app exception

Traceback (most recent call last):

File "/home/adminuser/venv/lib/python3.9/site-packages/rpm/init.py", line 102, in

_shim_module_initializing_

NameError: name 'shim_module_initializing' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 565, in _run_script

exec(code, module.__dict__)

File "/mount/src/os_explore/app.py", line 61, in

import rpm

File "/home/adminuser/venv/lib/python3.9/site-packages/rpm/init.py", line 105, in

initialize()

File "/home/adminuser/venv/lib/python3.9/site-packages/rpm/init.py", line 94, in initialize

raise ImportError(

ImportError: Failed to import system RPM module. Make sure RPM Python bindings are installed on your system.

I would really Appreciate help here as I am stuck on installing Java from days and literally sick & tired of it. My PySpark code is ready in my local app but unable to install Java on cloud.

4
  • Please do not post images of code, data, error messages, etc. Copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. Code or sample data in images can't be copied and pasted in order to search about a problem or reproduce it. For more details read the Meta FAQ entry Why not upload images of code/errors when asking a question? Commented Sep 29, 2023 at 13:44
  • @aled I have used image since it shows both App output & error side by side. And I have put most of code as code here in this post. Commented Sep 29, 2023 at 15:09
  • You didn't share the errors as text. This is part of Stackoverflow guidelines that I mentioned above. Commented Sep 29, 2023 at 16:51
  • @aled have updated post with error as text Commented Sep 30, 2023 at 5:13

2 Answers 2

1

Exception in the screenshot indicates that you do not have rmp package installed on your python environment.

To install this package you should modify you environment file if you are using it by adding this dependency: rpm

or install it with a shell script

pip install rpm

You might also need bindings as well: python-rpm

But if you are installing this rpm package using external shell command, maybe you do not need rpm-python package?

Sign up to request clarification or add additional context in comments.

3 Comments

I am not sure why I am getting this error because I am already using import rpm and I am not sure if I am using any shell command to install rpm.
import rpm is part of your python code. If you do not have this package in your environment, you will not be able to import it into your script.
yes I agree. I am not sure how to include shell script in streamlit but will try to figure out... thanks for helping me out and giving me a direction for further steps.
0

For your specific script, I don't see the rpm module being used anywhere, so you should be able to remove the import statement that's causing the exception. You're using the 'rpm' command through subprocess instead of the Python bindings.

For the error though, I found that on my system this was happening because my '/usr/bin/python3' was a different minor version than the python I was running the script with. In my case, 'python3' called python3.8, but calling /usr/bin/python3 called python3.6. This matters because the rpm module calls f"/usr/bin/python{majorver}" when checking for an existing RPM module to use.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.