Jason Susanto
Jason Susanto

Reputation: 101

Trying to install version 0.1.0.post1 but not available on Azure App Service

I am using kaleido==0.1.0.post1 (which works on local) in my python plotly dash web app and deploying this on Azure App Service with the configuration of the app service as:

python: 3.12.6
pip: 24.2

And I am getting this error when deploying on Azure, which seems like it can't find this version:

ERROR: No matching distribution found for kaleido==0.1.0.post1
ERROR: Could not find a version that satisfies the requirement kaleido==0.1.0.post1 (from versions: 0.0.1rc3, 0.0.1rc4, 0.0.1rc5, 0.0.1rc6, 0.0.1rc8, 0.0.1rc9, 0.0.1, 0.0.2, 0.0.3, 0.0.3.post1, 0.1.0a2, 0.1.0a3, 0.1.0, 0.2.0rc1, 0.2.0, 0.2.1, 0.4.0rc1, 0.4.0rc2, 0.4.0rc3, 0.4.0rc4, 0.4.0rc5, 1.0.0rc0)

Out of all these version I have tried 0.2.0, 0.2.1 and both of these are leading to hang state. I have also tried 0.1.0 and this gives me an error of:

ValueError:
The kaleido executable is required by the kaleido Python library, but it was not included
in the Python package and it could not be found on the system PATH.

Searched for included kaleido executable at:
    C:\Code\python.pptx.tester\.venv\Lib\site-packages\kaleido\executable\kaleido

And as I have opted to use version 1.0.0rc0 in the meantime, but I am getting this error when using the deployed web app:

Kaleido now requires that chrome/chromium is installed separately. Kaleido will try to detect it automatically, but the environmental error "BROWSER_PATH" can also be set.

What can I do to fix this issue (above)?

Is there any fix that I can do to deploy my app and use kaleido for static image rendering in the meantime until Kaleido2 is out? This would be very helpful, thanks!

Note: Here is my requirements.txt file:

dash==2.17.0
numpy==1.26.4
pandas==2.1.4
dash-mantine-components==0.14.4
dash-ag-grid==31.2.0
python-dotenv==1.0.1
dash-iconify==0.1.2
dash-bootstrap-components==1.6.0
pyspark==3.5.1
pytz==2024.1
scipy==1.14.0
azure-monitor-opentelemetry==1.6.4
opentelemetry-api==1.28.1
opentelemetry-sdk==1.28.1
msal==1.30.0
python-pptx==1.0.2
# kaleido==0.1.0.post1
kaleido==1.0.0rc0

Lastly, the code snippet where its failing is here:

import plotly.graph_objects as go
import pandas as pd
from base64 import b64encode
import plotly

def plotting_function():
    fig = go.Figure()

    # Some scatter plotting etc.

    if save:
        img_bytes = fig.to_image(format="jpeg")
        encoding = b64encode(img_bytes).decode()
        img_b64 = "data:image/jpeg;base64," + encoding
        return img_b64
    else:
        return fig

Furthermore this is my Azure App Service configuration:

enter image description here

And this is my build&deploy.yml file that I use to deploy the code:

trigger: 
  branches:
    include:
      - main

pr:
  autoCancel: false
  branches:
     include:
     - develop
 
pool:
  vmImage: 'ubuntu-latest'
 
variables:
  pythonVersion: '3.12' 
 
stages:
- stage: ArchiveArtifact
  jobs:
  - job:
    steps:
    - task: UsePythonVersion@0
      inputs:
        versionSpec: '$(pythonVersion)'
        addToPath: true

    - script: |
        sed 's/\${GITHUB_TOKEN}/'"$(GitHubToken)"'/' requirements.txt > temp_requirements.txt
        mv temp_requirements.txt requirements.txt
      displayName: 'Replace GitHub token in requirements.txt'
 
    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.SourcesDirectory)'
        includeRootFolder: false
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true
 
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'
 
- stage: DeployDev
  displayName: 'Deploy to Dev'
  dependsOn: ArchiveArtifact
  jobs:
  - deployment: DevDeploy
    pool: 'my-linux-agents'
    environment: 'dev'
    strategy:
     runOnce:
       deploy:
        steps:
        - task: AzureWebApp@1
          inputs:
            azureSubscription: 'my-azure-subscription'
            appType: 'webAppLinux'
            appName: 'my-python-web-app'
            package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
            deploymentMethod: 'auto'

Upvotes: 0

Views: 121

Answers (1)

Sirra Sneha
Sirra Sneha

Reputation: 1077

Thanks @EricLavault for the comment, it's true that Kaleido runs a headless instance of Chrome to render and save figures.

I created sample python plotly dashboard web app, I got the same error python Kaleido now requires that chrome/chromium is installed separately

  • To resolve the issue, as @EricLavault mentioned you can run your app in a container or VM with chrome browser installed.
  • I tried using container to install the chromium and it worked successfully.

In dockerfile I wrote the below command to install the chromium.

RUN apt-get update && apt-get install -y \
    chromium \
    chromium-driver \
    && apt-get clean
 
ENV BROWSER_PATH=/usr/bin/chrom

My complete Dockerfile:

FROM python:3.12-slim
 
RUN apt-get update && apt-get install -y \
    chromium \
    chromium-driver \
    && apt-get clean
 
ENV BROWSER_PATH=/usr/bin/chromium
 
COPY requirements.txt .
RUN pip install -r requirements.txt
 
COPY . /app
WORKDIR /app
EXPOSE 8000

CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]

app .py:

from flask import app
import plotly.graph_objects as go
import pandas as pd
from base64 import b64encode
import plotly
import os

def plotting_function(save=False):
       data = {
       'x': [1, 2, 3, 4, 5],
       'y': [10, 11, 12, 13, 14]
   }
   df = pd.DataFrame(data)

   fig = go.Figure(data=go.Scatter(x=df['x'], y=df['y'], mode='markers'))

   fig.update_layout(
       title="Sample Scatter Plot",
       xaxis_title="X Axis",
       yaxis_title="Y Axis"
   )
   if save:
       img_bytes = fig.to_image(format="jpeg")  
       encoding = b64encode(img_bytes).decode()  
       img_b64 = "data:image/jpeg;base64," + encoding 
       return img_b64
   else:
       return fig  
img_b64 = plotting_function(save=True)
print(img_b64)
fig = plotting_function(save=False)
fig.show()
  • Run the below command to build the docker image
docker build -t <ImageName> . 
  • Now push the built image to Azure container registry by running the below commands.
docker tag <ImageName> <AzureContainerRegistryName>.azurecr.io/<Imagename>:<tagName>
docker push <AzureContainerRegistryName>.azurecr.io/<ImageName>:<tagName>

Now you can successfully deploy your application to Azure Web App or Azure container Apps.

I've successfully deployed the app to Azure Web App and got the image.

Log stream : enter image description here

Upvotes: 1

Related Questions