环境:本地Win10 Pycharm;远程Ubuntu16.04,python3.5.2,opencv3.4.2
代码:
import cv2
img = cv2.imread('./1.jpg')
cv2.imshow('title',img)
cv2.waitKey(0)
报错:
Failed to connect to Mir: Failed to connect to server socket: No such file or directory
Unable to init server: Could not connect: Connection refused
(title:6261): Gtk-WARNING **: cannot open display:
Process finished with exit code 1
原因:
1,可能是Python Interpreter 发生了修改,需要删除之前的Interpreter,重新新建。
2,本地DISPLAY环境变量设置不对或者未设置。
解决:按照原因分析
1,参考:https://blog.csdn.net/qxqxqzzz/article/details/100977232
2,在Pycharm菜单栏: File->Settings->Build, Execution, Deployment->Console->Python Console->Environment Variables和 Run->Edit Configurations...->Configuration->Environment Variables中设置本地显示DISPLAY变量:IP地址:0.0,参考:https://blog.csdn.net/qxqxqzzz/article/details/100556075
3,如果上面两个都做了还不行,比如没有在本地显示图片,只显示Process finished with exit code 0然后就闪退了,请重复操作1和2,重新再试几次。
其他: