我正在docker容器中运行一些python代码,定义如下:
FROM continuumio/anaconda2:5.3.0
USER root
RUN apt-get install git
ENV AWS_DEFAULT_REGION us-east-2
# Copying code in container
RUN mkdir /warburg-investigation
COPY . /warburg-investigation
RUN apt-get update
# Installing necessary packages
RUN pip install panaxea
# Launching
ENV PYTHONPATH "${PYTHONPATH}:/warburg-investigation"
RUN cd warburg-investigation; python Main.py --pysparse
在我的一个脚本中,将matplotlib导入为:
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use("Agg")
plt.switch_backend("agg")
原因:
File "/opt/conda/lib/python2.7/site-packages/matplotlib/backends/qt_compat.py", line 158, in <module>
raise ImportError("Failed to import any qt binding")
ImportError: Failed to import any qt binding
鉴于:
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
plt.switch_backend("agg")
有什么建议吗?为什么?后者有效,但不会通过PEP8验证,因为它会引发:
E402 module level import not at top of file
由于matplotlib API特定,不可能轻松实现您想要的。以下是相关的doc:
所以,你可以试着在这种特殊情况下抑制PEP8,好吧,这是可能的
相关问题 更多 >
编程相关推荐