import _tkinter in Google CloudPlatforms

2019-08-21 07:45发布

问题:

In my python application i am using the matplotlib.when i start running it throws me an error:

ImportError: No named '_tkinter', please install the python3-tk package

Then i have installed sudo apt-get install python-tk.It got works in localhost.But same app i am deploying into the google cloudPlatforms.But i am getting this error:

import _tkinter # If this fails your Python may not be configured for Tk ImportError: libBLT.2.5.so.8.6: cannot open shared object file: No such file or directory

How to install python-tk to Google cloudPlatforms.After deactivate the vitualenv also i have installed.It shows already the newest version.I have tried many things but it doesn't seems to work.The App throws 502 Bad Gateway.

Thanks in advance.

回答1:

Use

matplotlib.use('agg')

right after importing matplotlib, to render matplotlib graphics in a headless environment. You can also set this as the default in your matplotlibrc file, or via the MPLBACKEND environment variable.

See the matplotlib docs for more details: https://matplotlib.org/faq/usage_faq.html#what-is-a-backend See also the page on using matplotlib in a web application.