Install java module for python

Hello
I am new on Docker

My host linux is Ubuntu 22.4

I am trying to build a container within which I will be able to run python with a java module.
My Dockerfile is as follows:

FROM ubuntu:latest
WORKDIR /app
RUN apt-get update && apt-get install -y python3-pip
RUN pip3 install java
COPY error_check.py .
COPY run_test.sh .
COPY java-test-cases /app/java-test-cases
CMD ["bash", "run_test.sh"]

When trying to build the image, I get the below errors:
ERROR [4/7] RUN pip3 install java

[4/7] RUN pip3 install java:                                                                                                                                                                                    
4.022 error: externally-managed-environment                                                                                                                                                                        
4.022                                                                                                                                                                                                              
4.022 × This environment is externally managed                                                                                                                                                                     
4.022 ╰─> To install Python packages system-wide, try apt install
4.022     python3-xyz, where xyz is the package you are trying to
4.022     install.
4.022     
4.022     If you wish to install a non-Debian-packaged Python package,
4.022     create a virtual environment using python3 -m venv path/to/venv.
4.022     Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
4.022     sure you have python3-full installed.
4.022     
4.022     If you wish to install a non-Debian packaged Python application,
4.022     it may be easiest to use pipx install xyz, which will manage a
4.022     virtual environment for you. Make sure you have pipx installed.
4.022     
4.022     See /usr/share/doc/python3.12/README.venv for more information.
4.022 
4.022 note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
4.022 hint: See PEP 668 for the detailed specification.
Dockerfile:6
   4 |     
   5 |     RUN apt-get update && apt-get install -y python3-pip
   6 | >>> RUN pip3 install java
   7 |     COPY error_check.py .
   8 |     COPY run_test.sh .
--------------------
ERROR: failed to solve: process "/bin/sh -c pip3 install java" did not complete successfully: exit code: 1

How can i resolve the errors?


Please, format your post according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
echo "I am a code."
echo "An athletic one, and I wanna run."
```

Hello,
I have reformatted it.

Is this possible at all? What would it be? Python and Java are two different programming language and pip is for python packages. Is there some python package that makes it possible to call a java module for example?

Have you tried to search for the error message?

error: externally-managed-environment  

I would also recommend using a PYthon base image so you can install a specific Python version instead of the one that the latest ubuntu supports which is different in every version.

https://hub.docker.com/_/python

It will still not install java