我几个小时以来一直在讨论这个问题,但我无法确定发生此错误的原因。 我试图在我的apache2服务器中运行一个简单的python脚本 -
#!/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' )
我收到以下错误(附截图)
我尝试通过pip和conda install安装matplotlib。我也试过添加
sys.path.insert(0,"/usr/local/lib/python3.5/dist-packages")
和
sys.path.insert(0, "/home/aswin/anaconda3/lib/python3.6/site-packages")
,如上面的代码所示,
但似乎没有什么能解决这个问题。我正在运行lubuntu btw。
非常感谢任何帮助。 :) screenshot of localhost
答案 0 :(得分:0)
我有类似的问题,并通过升级matplotlib