在 Web 应用程序服务器中使用 maptlotlib 时遇到问题 (php)
Trouble using maptlotlib in web application server (php)
我有一个 python 程序,其开头为:
from optparse import OptionParser
import math
#import wx
import os
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from numpy import *
import scipy as scipy
from scipy import *
from scipy import constants
import scipy.signal as signal
import matplotlib.pyplot as plt
当我尝试用 php 打开它时出现错误。
我已经用谷歌搜索了,显然如果我在导入 pylab 或 pyplot 之前这样做:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
问题应该已经解决了。但我得到的错误是:
/usr/lib/pymodules/python2.7/matplotlib/__init__.py:923: UserWarning: This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time
知道发生了什么事吗??
默认后端在 matplotlibrc
文件中指定 -- 您可以尝试在那里更改它。
也可能是您 运行 python 所处的任何环境都可能已经导入 matplotlib 并将后端指定为配置的一部分。此外,some post 建议可能需要以下行:
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'
我有一个 python 程序,其开头为:
from optparse import OptionParser
import math
#import wx
import os
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
from numpy import *
import scipy as scipy
from scipy import *
from scipy import constants
import scipy.signal as signal
import matplotlib.pyplot as plt
当我尝试用 php 打开它时出现错误。 我已经用谷歌搜索了,显然如果我在导入 pylab 或 pyplot 之前这样做:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
问题应该已经解决了。但我得到的错误是:
/usr/lib/pymodules/python2.7/matplotlib/__init__.py:923: UserWarning: This call to matplotlib.use() has no effect
because the the backend has already been chosen;
matplotlib.use() must be called *before* pylab, matplotlib.pyplot,
or matplotlib.backends is imported for the first time
知道发生了什么事吗??
默认后端在 matplotlibrc
文件中指定 -- 您可以尝试在那里更改它。
也可能是您 运行 python 所处的任何环境都可能已经导入 matplotlib 并将后端指定为配置的一部分。此外,some post 建议可能需要以下行:
os.environ[ 'MPLCONFIGDIR' ] = '/tmp/'