When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.

** "First pattern recognition" reading party ** is about to end, so I talked about what to read in the next series, "Practical Computer Vision ”has appeared.

It's just stored in my house, so I thought I'd pull it out and read it for a while, but I was addicted to creating the environment. And for a reason that doesn't really matter. Pathetic ...

Make a note so that no one will follow the same rut.

environment

Before installing PIL

I can install it by pip install PIL without thinking about anything, but when I read the jpeg file and try to show it with pylab, I get the following error.

IOError: decoder jpeg not available

I was told that there is no jpeg decoder, so when I googled it, it seems that libjpeg-dev needs to be installed. However, when I sudo apt-get install libjpeg-dev, I was angry with "I already have it!".

When libjpeg-dev is installed with apt, libjpeg.so is created under / usr / lib / x86_64-linux-gnu /, but it seems that this folder is not seen when installing PIL with pip.

So, let's put a symbolic link where you can see it from pip.

sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so

After linking, I reinstalled PIL and it worked fine.

reference

http://atasatamatara.hatenablog.jp/entry/20120723/1343044059

Before installing matplotlib

matplotlib can also be entered with pip. Numpy is also included because of the dependency.

However, nothing is displayed when pylab.show () is executed. I don't even get an error. What is this? ?? ??

After investigating, it seems that the backend for screen display is set appropriately. As for where to set it, there is a file called matplotlibrc. The following command will tell you the location.

>>> import matplotlib
>>> matplotlib.matplotlib_fname()

matplotlibrc


backend      : agg

With a backend called agg, you can write to a file, but you can't open a window and display it on the screen.

Actually, matplotlib is also included in system-wide python, but when I look at that matplotlibrc, the backend is Tkagg. It looks like you're using Tkinter.

So I will rewrite from agg to Tkagg. Then, the following error came to appear this time.

No module named _tkagg

It seems that the file _tkagg.py is not generated when compiling matplotlib. To solve this, you need to install tk-dev.

sudo apt-get install tk-dev

This time it will be under / usr / lib, so there is no need to put a link. If you install matplotlib after installing tk-dev, you can do it.

Summary

I wrote it in the order I tried various things by groping, but it should be set up like this.

sudo apt-get install libjpeg tk-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/libjpeg.so

pip install PIL
pip install matplotlib

vim /path/to/your/matplotlibrc
###Rewrite backend to Tkapp

By the way, if you google, the information will come out as it is, but because I decided that "If it is a system-wide matplotlib, it will be displayed properly with tk, so there is no reason why tk-dev is not included" and did not confirm it. I'm addicted to it.

I don't remember how it happened, but maybe when I put it in system wide, it was apt, and since I put it in binary, _tkagg was included even without tk-dev ...

Recommended Posts

When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
What I was addicted to when creating a web application in a windows environment
What I was addicted to when dealing with huge files in a Linux 32bit environment
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
When I tried to create a virtual environment with Python, it didn't work
I set up TensowFlow and was addicted to it, so make a note
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
What I was addicted to when combining class inheritance and Joint Table Inheritance in SQLAlchemy
I stumbled when I tried to install Basemap, so a memorandum
When I tried to build a Rails environment on WSL2 (Ubuntu 20.04LTS), I stumbled and fell.
When I tried to install Ubuntu 18.04, "Initramfs unpacking failed: Decoding failed" was displayed and the startup failed.
The story I was addicted to when I specified nil as a function argument in Go
A memorandum when I tried to get it automatically with selenium
A note I was addicted to when making a beep on Linux
A note I was addicted to when creating a table with SQLAlchemy
I want to create a pipfile and reflect it in docker
I was addicted to confusing class variables and instance variables in Python
I was addicted to pip install mysqlclient
I tried putting virtualenv in Cygwin environment
When I tried to run Python, it was skipped to the Microsoft Store
A story I was addicted to when inserting from Python to a PostgreSQL table
A story I was addicted to trying to install LightFM on Amazon Linux
I was addicted to creating a Python venv environment with VS Code
The file name was bad in Python and I was addicted to import
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
[Python] How to save the installed package and install it in a new environment at once Mac environment
[Introduction to json] No, I was addicted to it. .. .. ♬
When I try matplotlib in Python, it says'cairo.Context'
When I tried to make a VPC with AWS CDK but couldn't make it
Three things I was addicted to when using Python and MySQL with Docker
Docker x visualization didn't work and I was addicted to it, so I summarized it!
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
[Words spelled to me when I was in the first grade ①] I'm not afraid to build a programming environment.
I tried to implement a pseudo pachislot in Python
I was addicted to scraping with Selenium (+ Python) in 2020
[Go + Gin] I tried to build a Docker environment
A story that I was addicted to at np.where
I was able to repeat it in Python: lambda
I was addicted to trying logging.getLogger in Flask 1.1.x
What I was addicted to when using Python tornado
I tried to install scrapy on Anaconda and couldn't
I was soberly addicted to calling awscli from a Python 2.7 script registered in crontab
Note that I was addicted to npm script not passing in the verification environment
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
I tried to make the phone ring when it was posted at the IoT post
When a voice-analyzed amateur listened to anti-phase music, it was confusing and quiet to visit.
What I did when I was angry to put it in with the enable-shared option
A beginner tried coloring line art with chainer. I was able to do it.
Memo A beginner tried to build a Java environment and Japaneseize it on Ubuntu 18.04.2 LTS.
[IOS] GIF animation with Pythonista3. I was addicted to it.
I tried the super-resolution algorithm "PULSE" in a Windows environment
I tried to implement a one-dimensional cellular automaton in Python
When I tried the AtCoder Beginner Contest, it was a terrible result, so I look back
When creating a pipenv environment, I got addicted to "Value Error: Not a valid python path"
I was surprised to receive a nice review when I wrote Python to CheckIO and its explanation
Since there was a doppelganger, I tried to distinguish it with artificial intelligence (laugh) (Part 2)
I tried "How to get a method decorated in Python"
I made a server with Python socket and ssl and tried to access it from a browser
I tried to illustrate the time and time in C language
What I was addicted to when migrating Processing users to Python