How to Install Python to Run Aspose.Cells for Python via Java

This tutorial provides detailed steps on how to install python to run Aspose.Cells for python via java. It assumes that you have installed Docker on your system and guides you to install all the necessary software required to run Aspose-Cells code in Python. You will install Python during these steps and create a new XLSX file to verify the established environment.

Steps to Install Python to Run Aspose.Cells for Python via Java

  1. Using docker command pull the latest image of Ubuntu
  2. Run the Ubuntu image using the docker command
  3. Install Sudo command
  4. Install Java
  5. Install Python
  6. Install Pip command
  7. Install Aspose-Cells and JPype1
  8. Write and run the Aspose-Cells code for Python to create a workbook

Note that these steps assume that you are using Docker to test the complete environment however if you do not want to use Docker, ignore the first two steps and run the rest of the commands in the terminal or command prompt in your Linux environment. You need to install Python and Pip3 to install Aspose-Cells and JPype1 for running the sample code given at the end of the following script.

Script to Install Python to Run Aspose.Cells for Python via Java

1. Pull Latest Ubuntu Image
docker pull ubuntu
2. Run Ubuntu Image Using Docker Command
docker run -it ubuntu
3. Install Sudo Command
apt update
apt upgrade
apt install sudo
sudo apt update
4. Install Java
sudo apt install default-jre
5. Install Python
sudo apt update
sudo apt upgrade
sudo apt install -y python3
6. Install Pip Command
sudo apt update
sudo apt install python3-pip
7. Install Aspose-Cells
pip install aspose-cells
pip install JPype1
8. Write Sample Program And Save It As Sample.Py And Run Program
python3 sample.py
SAMPLE CODE TO BE WRITTEN IN Sample.Py
import jpype
import asposecells
jpype.startJVM()
from asposecells.api import Workbook
# Instantiate a blank XLSX workbook
wb = Workbook()
# Save Excel file to check the environment
wb.save("new-workbook.xlsx")
jpype.shutdownJVM()

There is no need to follow or run all the steps as if you have an Ubuntu image or have Ubuntu installed in your environment then leave the first two steps. If the Sudo command is installed in your environment leave it up to step 3. If Java is also installed, leave up to step 4 and you may just install Python and follow the rest of the steps.

As an alternate, you may paste the following content in the Dockerfile.

# Use the Ubuntu base image
FROM ubuntu:latest
# Set non-interactive mode during package installation
ENV DEBIAN_FRONTEND=noninteractive
# Update and install packages
RUN apt-get update && \
apt-get install -y sudo software-properties-common vim && \
apt-get install -y openjdk-11-jdk python3 python3-pip && \
pip3 install --upgrade pip && \
apt-get clean
# Install Aspose.Cells dependency
RUN apt-get update && \
apt-get install -y libgdiplus && \
apt-get clean
# Install JPype1
RUN pip3 install JPype1
# Install aspose-cells
RUN pip3 install aspose-cells
# Add a non-root user with sudo privileges
RUN useradd -m dockeruser && \
echo "dockeruser ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/dockeruser && \
chmod 0440 /etc/sudoers.d/dockeruser
# Set the user
USER dockeruser
# Set the working directory
WORKDIR /home/dockeruser
# Example: Copy your application files if needed
# COPY . /home/dockeruser/app
# CMD [ "bash" ] # You can replace this with the actual command to run your application
# Build command: docker build -t my-custom-image .
# Run command: docker run -it my-custom-image

Build the image using the following command while moving the control to the folder where Dockerfile is placed:

docker build -t cells-python-image .

Run the image

docker run -it cells-python-image

In the end, a sample code is given to test the installation. You may save this code in the sample.py file after completing the tasks up to step 7 and then run the command given under step 8.

 English