Anchormen / wsl2-gpu

8 stars 3 forks source link

Issue with PIL import Image #1

Open nabriis opened 3 years ago

nabriis commented 3 years ago

Hi using this image for R on windows WSL 2 I seem to run into an issue with "Pillow" not being installed when running some ML code in rstudio.

I tried reticulate::py_install('pillow',pip = TRUE)

but get the following error Error: could not find a Python environment for /usr/local/bin/python

Even though we have

> reticulate::py_config()
python:         /usr/local/bin/python
libpython:      /usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so
pythonhome:     //usr://usr
version:        3.6.9 (default, Nov  7 2019, 10:44:02)  [GCC 8.3.0]
numpy:          /usr/local/lib/python3.6/dist-packages/numpy
numpy_version:  1.18.1
tensorflow:     /usr/local/lib/python3.6/dist-packages/tensorflow

In the Jupyter notebook this code returns the same path:

import sys
from PIL import Image
sys.modules['Image'] = Image 
from PIL import Image
print(Image.__file__)
import Image
print(Image.__file__)

So it seems to be an issue with rstudio not finding the pillow install somehow.

angelsevillacamins commented 3 years ago

Dear Nabriis, Dependency management in tricky in this scenario since rstudio is running with the ubuntu user but the installation is carried out as root. I think that you have two options:

  1. Change the Dockerfile adding the new dependencies: For that modify the line that reads:

    RUN pip install rpy2

    to:

    RUN pip install rpy2 pillow

    Create again the image using this new Dockerfile and push it to Dockerhub. This option will persist the changes and it is my favorite.

  2. Get a bash shell in the container and then run as root:

    pip install pillow

    However, this option won't persist your changes and you have to run it every time that you restart the container. Let me know if that solve your problem.