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

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. Commented Apr 23, 2017 at 11:49
  • Also, this may help: stackoverflow.com/questions/30196585/… Commented Apr 23, 2017 at 12:00

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.