Bug----QXcbConnection: Could not connect to display Aborted (core dumped)

本文介绍了一种在没有图形界面的环境下使用Matplotlib而不遇到显示错误的方法。通过设置环境变量QT_QPA_PLATFORM为offscreen,可以避免因缺少图形界面而导致的连接失败问题。

Question:

 1 fenglei@gpu01:~$ ipython
 2 Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06)
 3 Type "copyright", "credits" or "license" for more information.
 4 
 5 IPython 5.1.0 -- An enhanced Interactive Python.
 6 ?         -> Introduction and overview of IPython's features.
 7 %quickref -> Quick reference.
 8 help      -> Python's own help system.
 9 object?   -> Details about 'object', use 'object??' for extra details.
10 
11 In [1]: import matplotlib.pyplot as plt
12 
13 In [2]: QXcbConnection: Could not connect to display
14 Aborted (core dumped)

Solution:

 1 fenglei@gpu01:~$ ipython
 2 Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul  2 2016, 17:53:06)
 3 Type "copyright", "credits" or "license" for more information.
 4 
 5 IPython 5.1.0 -- An enhanced Interactive Python.
 6 ?         -> Introduction and overview of IPython's features.
 7 %quickref -> Quick reference.
 8 help      -> Python's own help system.
 9 object?   -> Details about 'object', use 'object??' for extra details.
10 
11 In [1]: import os
12 
13 In [2]: os.environ['QT_QPA_PLATFORM']='offscreen'
14 
15 In [3]: import matplotlib.pyplot as plt

 

转载于:https://www.cnblogs.com/smile-sunshine/p/8431441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值