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

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
博客园 - 叶小钗
爱范儿
爱范儿
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队
T
Tailwind CSS Blog
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell

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#