1

While deploying in Heroku and adding customized buildpacks such as libspatialindex, another error occurred where Python 3.5 now looks for Tkinter.

Locally, by installing using sudo apt-get tk-dev this would be solved and trying out the suggestion from this similar problem: import matplotlib failing on Heroku, the error still persists.

Here are my buildpacks:

https://github.com/heroku/heroku-buildpack-apt 
heroku/python
https://github.com/julienfr112/libspatialindex-buildpack.git

And my Aptfile containing only:

python3-tk
libpq-dev
build-essential
libncursesw5-dev
libreadline5-dev
libssl-dev
libgdbm-dev
libc6-dev
libsqlite3-dev tk-dev
libbz2-dev

On Heroku push here's the tail of the log:

2017-09-05T08:25:58.903075+00:00 app[web.1]:   File "/app/.heroku
/python/lib/python3.5/site-packages/six.py", line 82, in _import_module
2017-09-05T08:25:58.903076+00:00 app[web.1]:     __import__(name)
2017-09-05T08:25:58.903076+00:00 app[web.1]:   File "/app/.heroku
/python/lib/python3.5/tkinter/__init__.py", line 35, in <module>
2017-09-05T08:25:58.903076+00:00 app[web.1]:     import _tkinter 
# If this fails your Python may not be configured for Tk
2017-09-05T08:25:58.903077+00:00 app[web.1]: ImportError: No module
named '_tkinter'

Any ideas?

Reiion
  • 923
  • 3
  • 15
  • 33
  • When you push to Heroku do you see anything that looks like `apt` activity in the build output? – ChrisGPT was on strike Sep 05 '17 at 12:37
  • @Chris yes the logs seems to run and install the files that are contained in the aptfile. – Reiion Sep 05 '17 at 12:47
  • From the accepted answer in the question you linked to: "Unfortunately, this Aptfile doesn't have the same dependency resolution so you will have to specify any other packages manually." Have you also installed Tk itself? I'm not sure what other dependencies might exist… – ChrisGPT was on strike Sep 05 '17 at 13:44
  • @Chris by tk itself tk-dev? so far my aptfile contains the following: python3-tk libpq-dev build-essential libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev libsqlite3-dev tk-dev libbz2-dev – Reiion Sep 05 '17 at 14:06
  • I don't know exactly what's required. That's why I added a comment instead of an answer. I'm somewhat confused by the line I quoted above since `apt` with dependency resolution is _much_ more useful than it is without. I hope to see Heroku enhance that buildpack accordingly. – ChrisGPT was on strike Sep 05 '17 at 14:10
  • You can't use tkinter from a web server, if that's what you're trying to do. – Bryan Oakley Sep 06 '17 at 17:39
  • Did you get this problem solved? i am also getting the same issue @Reiion – lalithkumar Nov 02 '17 at 09:04
  • @lalithkumar actually no... – Reiion Nov 02 '17 at 09:05
  • what did you do to come over this? @Reiion – lalithkumar Nov 02 '17 at 09:05
  • @lalithkumar I stopped creating my deployment at the moment. I plan to redo everything after finishing the application altogether. If this still shows up again, I guess I could focus then on this particular problem – Reiion Nov 02 '17 at 09:07
  • ok post the answer if you get solved in future @Reiion – lalithkumar Nov 02 '17 at 09:07

1 Answers1

1

Change the matplotlib backend from tkinter to something else. At the very beginning of the program do this:

import matplotlib
matplotlib.use('Agg')

This way the rest of the program will use the backend that you set ('Agg', 'SVG', etc, etc)

Another option would be to try and mess with the The matplotlibrc file per: https://matplotlib.org/users/customizing.html#the-matplotlibrc-file

mgcdanny
  • 1,082
  • 1
  • 13
  • 20