惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
爱范儿
爱范儿
量子位
N
Netflix TechBlog - Medium
博客园 - 聂微东
博客园 - Franky
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Display Image with Pillow inside Ubuntu on Windows
2019-02-16 · via jdhao's digital space

With the help of Windows Subsystem for Linux (WSL, for short)1, we can use the nearly full Linux environment on Windows system. In this post, I would like to share how to display images inside Ubuntu on Windows, which is one of the popular distrubtions.

If you try to show an image with Pillow using the following code inside WSL:

from PIL import Image

im = Image.open("test.jpg")

im.show()

you will find that nothing happens if you run the above code. The reason is two-fold:

  1. There is no valid image viewer on your Ubuntu on Windows (Pillow will use the system default image viewer, which is Imagemagick on Linux)
  2. There is no X server by which you can use GUI applications.

After knowing the reasons, the solution is simple. First, we need to install Imagemagick for Ubuntu on Windows (not on Windows 10 itself, this is important!):

sudo apt install imagemagick

Then we need to install a X server on the Windows system, which will serve your GUI applications. A good option for Windows is Vcxsrv. You can install it manually or with the help of Chocolatey:

After install, run it on your system. Inside Ubuntu on Windows, you should also set the DISPALY environment variable in your .bashrc:

echo "export DISPLAY=localhost:0.0" >> ~/.bashrc && source ~/.bashrc

Run your Python code again and you should be able to see the image displayed properly on your screen.

References#