1

I have been busting my head over this for a few hours now but I cant nail down the reason why this error occurs. I am trying to run a simple python script in my apache2 server-

#!/usr/bin/python3.5

import cgi
import cgitb
cgitb.enable()
import sys
sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages")
sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages")

# HEADERS
print("Content-Type:text/html; charset=UTF-8")
print()  # blank line required at end of headers

# CONTENT
import numpy as np
import os

# set HOME environment variable to a directory the httpd server can write to
os.environ[ 'HOME' ] = '/tmp/'

import matplotlib
# chose a non-GUI backend
matplotlib.use( 'Agg' )

import pylab

#Deals with inputing data into python from the html form
form = cgi.FieldStorage()

# construct your plot
pylab.plot([1,2,3])

print("Content-Type: image/png\n")

# save the plot as a png and output directly to webserver
pylab.savefig( sys.stdout, format='png' )

and I get the following error(screenshot attached) I tried installing matplotlib via pip and also conda install.I also tried adding sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages") and sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages") as shown in the code above, but nothing seems to fix this issue. I am running lubuntu btw.

Any help would be much appreciated. :) screenshot of localhost

ag1
  • 21
  • 2
  • Don't add paths for two different python versions in the same script. Also get rid of `pylab`. Use `matplotlib.pyplot` instead, e.g. `import matplotlib.pyplot as plt; plt.plot([1,2])`. This may not be the cause for the error, but finding it with a clean script may be easier. – ImportanceOfBeingErnest Apr 23 '17 at 11:49
  • Also, this may help: http://stackoverflow.com/questions/30196585/matplotlib-import-error-no-module-named-path?rq=1 – ImportanceOfBeingErnest Apr 23 '17 at 12:00

1 Answers1

0

I had similar problem and it was fixed by upgrading the matplotlib

George Sotiropoulos
  • 1,864
  • 1
  • 22
  • 32