问题
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
回答1:
I had similar problem and it was fixed by upgrading the matplotlib
来源:https://stackoverflow.com/questions/43570626/importerror-no-module-named-matplotlib-path-when-running-a-python-script-in