SOLVED - ImportError: libjpeg.so.8: cannot open shared object file - On WSL

Just solved this, but posting for reference.

I’m trying to get the fast.ai library working inside my WSL (Windows Subsystem for Linux). My understanding is it’s supposed to work except for the GPU).

However, when I try to import fast.ai I get the following error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-adec07e3e53e> in <module>()
----> 1 from fastai.imports import *
  2 from fastai.torch_imports import *
  3 from fastai.structured import *
  4 from fastai.dataset import *
  5 from fastai.column_data import *

~/fast.ai2/fastai/imports.py in <module>()
 13 from pandas_summary import DataFrameSummary
 14 from IPython.lib.display import FileLink
---> 15 from PIL import Image, ImageEnhance, ImageOps
 16 from sklearn import metrics, ensemble, preprocessing
 17 

~/anaconda3/envs/fastai/lib/python3.6/site-packages/PIL/Image.py in <module>()
 54     # Also note that Image.core is not a publicly documented interface,
 55     # and should be considered private and subject to change.
---> 56     from . import _imaging as core
 57     if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
 58         raise ImportError("The _imaging extension was built for another "

ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory

It appears it can’t find this libjpeg.so.8 file.

Hence, I set variable LD_LIBRARY_PATH following: https://stackoverflow.com/questions/1099981/why-cant-python-find-shared-objects-that-are-in-directories-in-sys-path

  1. First I find the file:
    wbrucek@LAPTOP-SF5P3R2K:/etc$ apt-file search libjpeg.so.8
    libjpeg-turbo8: /usr/lib/x86_64-linux-gnu/libjpeg.so.8
    libjpeg-turbo8: /usr/lib/x86_64-linux-gnu/libjpeg.so.8.0.2
  2. Then I add it to the LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu
  3. Then I restarted jupyter notebook (in the same terminal)

Unfortunately this did not fix the error.

I checked and set the LD_LIBRARY_PATH directly inside jupyter notebook, without affecting the error.

image

1 Like

SOLUTION. In addition to what I did previously (i.e. setting LD_LIBRARY_PATH). What i figured out was that “apt-file search libjpeg.so.8” is actually showing that you need to install “libjpeg-turbo8” to get “libjpeg.so.8”.

So I installed it and everything works now!

sudo apt-get install libjpeg-turbo8

6 Likes

Thanks, works for me Ubuntu 16 GPU+ paperspace.

Thanks for figuring this out. It solved the problem for me on Ubuntu 16.04 within Docker.