【发布时间】:2020-06-21 15:20:40
【问题描述】:
我在 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
【问题讨论】:
标签: python docker matplotlib