OD1995
OD1995

Reputation: 1777

"ModuleNotFoundError: No module named 'tkinter'" when trying to use matplotlib in Azure

I am attempting to use matplotlib on a Python script in Azure, using a WebJob on a Web App. I am getting the error below:

enter image description here

The error is obviously when importing tkinter, but based on this, it appears tkinter is not available in Azure. This is not a problem for me, as when I use it, I am just creating a PNG, so I believe I don't actually need it.

How can I get around this problem?

Upvotes: 1

Views: 2122

Answers (3)

user9724030
user9724030

Reputation: 66

I solved this problem through this.

import matplotlib 
matplotlib.use('agg')
import matplotlib.pyplot as plt

Upvotes: 4

Peter Pan
Peter Pan

Reputation: 24128

According to the logs of your WebJob, you are using Azure WebApp for Windows to run it. Unfortunately, due to the Win32k.sys (User32/GDI32) Restrictions of Azure Web App sandbox, the job to create a PNG by matplotlib will never work for you, even after fix the current issue, because matplotlib requires GDI.

enter image description here

So I suggest that you can try to make the same Python script works on Linux and use crontab to trigger it, and to write a Dockerfile or build an Docker image for deployment on Azure WebApp for Linux. Please refer to the offical document Create a Python app in Azure App Service on Linux to get start.

Upvotes: 0

boostedd
boostedd

Reputation: 268

You can't install tkinter with sudo apt-get install python-tk?

I usually have to install the package this way before it will work.

Upvotes: 0

Related Questions