ImportError:在apache2中运行python脚本时没有名为“matplotlib._path”的模块

问题描述 投票:1回答:1

我现在已经在这几个小时了,但我无法确定发生此错误的原因。我试图在我的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

python-3.x ubuntu matplotlib apache2 cgi
1个回答
0
投票

我有类似的问题,它通过升级matplotlib修复

© www.soinside.com 2019 - 2024. All rights reserved.