<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Punita Goel</title>
    <description>The latest articles on DEV Community by Punita Goel (@punita_goel).</description>
    <link>https://dev.to/punita_goel</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3278958%2F4f14d1ec-bc59-4f0b-b01c-17c55ad9993d.jpg</url>
      <title>DEV Community: Punita Goel</title>
      <link>https://dev.to/punita_goel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/punita_goel"/>
    <language>en</language>
    <item>
      <title>Fixing the Graphviz Error on Google Cloud Run</title>
      <dc:creator>Punita Goel</dc:creator>
      <pubDate>Fri, 20 Jun 2025 07:48:21 +0000</pubDate>
      <link>https://dev.to/punita_goel/fixing-the-graphviz-error-on-google-cloud-run-7g6</link>
      <guid>https://dev.to/punita_goel/fixing-the-graphviz-error-on-google-cloud-run-7g6</guid>
      <description>&lt;p&gt;Deploying a Python app on Google Cloud Run with Graphviz visualizations can trigger:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;graphviz.backend.execute.ExecutableNotFound: failed to execute PosixPath('dot'), make sure the Graphviz executables are on your systems' PATH
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This happens because Cloud Run’s default build misses the &lt;code&gt;dot&lt;/code&gt; executable, even with a &lt;code&gt;Dockerfile&lt;/code&gt;. Here’s a quick fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up Dockerfile&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Create a &lt;code&gt;Dockerfile&lt;/code&gt; to install Graphviz:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM python:3.11-slim
WORKDIR /app
RUN apt-get update &amp;amp;&amp;amp; apt-get install -y graphviz
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["bash", "-c", "dot -V &amp;amp;&amp;amp; python app.py"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Uses Python 3.11 and installs &lt;code&gt;dot&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;graphviz&lt;/code&gt; to &lt;code&gt;requirements.txt&lt;/code&gt; manually.
&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;CMD&lt;/code&gt; checks &lt;code&gt;dot&lt;/code&gt; at runtime.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Configure cloudbuild.yaml&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Since the autogenerated Cloud Build doesn’t read the &lt;code&gt;Dockerfile&lt;/code&gt; by default, update &lt;code&gt;cloudbuild.yaml&lt;/code&gt; with debug and build steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;steps:
- name: 'python:3.11'
  args:
    - '-c'
    - &amp;gt;
      apt-get update -y &amp;amp;&amp;amp; \
      apt-get install -y graphviz &amp;amp;&amp;amp; \
      pip install --no-cache-dir graphviz &amp;amp;&amp;amp; \
      python -c 'import graphviz; from graphviz import Digraph; print("Graphviz Digraph imported:", Digraph)'
  dir: .
  id: install-and-debug
  entrypoint: bash
- name: 'gcr.io/cloud-builders/docker'
  args:
    - '-c'
    - |
      ls -l Dockerfile || echo "Dockerfile not found!"
      cat Dockerfile || echo "Failed to read Dockerfile!"
  id: debug-dockerfile
  entrypoint: bash
- name: 'gcr.io/cloud-builders/docker'
  args:
    - build
    - '-f'
    - Dockerfile
    - '-t'
    - &amp;gt;-
$_AR_HOSTNAME/$_AR_PROJECT_ID/$_AR_REPOSITORY/$REPO_NAME/$_SERVICE_NAME:$COMMIT_SHA
    - .
  dir: .
  id: build-image
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;install-and-debug&lt;/code&gt;: Installs Graphviz and tests the Python import.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;debug-dockerfile&lt;/code&gt;: Checks if the &lt;code&gt;Dockerfile&lt;/code&gt; exists and reads it.
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;build-image&lt;/code&gt;: Builds the image using the &lt;code&gt;Dockerfile&lt;/code&gt;, tagging it with your project details.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Deploy and Fix Runtime&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Deploy with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcloud run deploy SERVICE_NAME --source . --platform managed --region REGION --no-cache
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the error persists, add to &lt;code&gt;app.py&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PATH&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/usr/bin:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PATH&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check logs (&lt;code&gt;gcloud run logs read&lt;/code&gt;) to confirm &lt;code&gt;dot&lt;/code&gt; works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why It Works&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;code&gt;cloudbuild.yaml&lt;/code&gt; ensures Graphviz is installed, the &lt;code&gt;Dockerfile&lt;/code&gt; sets it up for runtime, and the PATH fix resolves any execution issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Your Project&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This fix enables your project’s visualizations on Google Cloud.&lt;/p&gt;

&lt;p&gt;Quick and done—test it now!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
