Azure Web App Python matplotlib - Tcl doesn't work inside a virtualenv

Azure Web App Python matplotlib - Tcl doesn't work inside a virtualenv


I tried to run flask app in Azure that generates matplotlib pie charts and save them as PNG. However I encountered on two serious issues.

First when I set up all the packages in the virtual environment and deployed to Azure I got the following error:
Can't find a usable init.tcl in the following directories: D:/Python27/lib/tcl8.5 D:/lib/tcl8.5 D:/lib/tcl8.5 D:/library D:/library D:/tcl8.5.15/library D:/tcl8.5.15/library This probably means that Tcl wasn't installed properly.
Second was that I had to do some magic to get numpy, matplotlib, pylab, scipy for windows which appeared to be challenge because pip was trying to compile them, but it failed every time I fixed the previous exception. If you would like to know how you can install these packages the lazy way on a Azure or PTVS for Visual Studio on Windows follow this link. After some search I have found this brilliant discussion on Github https://github.com/pypa/virtualenv/issues/93 , but yet none of the solutions there worked on Azure. I am using Visual Studio with PTVS to deploy on Azure. The studio generates has his own powershell activate.ps1 script in the virtual environment so I thought that modifying the ps as it is done on the above url would do the job on Azure as well, but it didn't work. I already new that virtualenv does not copy the Tcl library to the new virtualenv, but instead adds a reference to the PYTHONPATH and I also knew form the exception above where my python resides on the Azure hard drive. You can also execute something dumm like this to get the Python local path:

@app.route('/vars')
def vars():
    return 'sys.prefix=' + sys.prefix
So now the main goal is to add the PATH variables to the Azure Web App. Here is how: - Connect to the old Azure UI portal https://manage.windowsazure.com - Find your web app - Go to configure - Find the app settings Velin Georgiev blog imageVelin Georgiev blog image Set your environment variables
TCL_LIBRARY D:\Python27\tcl\tcl8.5 TK_LIBRARY D:\Python27\tcl\tk8.5
Posted on

Tags: Python, Flask, Azure, virtualenv, Azure Web App, matplotlib, Tcl doesn't work

Comments
anonymous user | 17 Mar 2016

Thanks! This was really helpful & a life saver. And just to add that in the new portal, you can do the same thing by selecting settings > application settings > app settings.