Why does Python sometimes fail from importing a PIL image and importing Image?

The following code snippet seems unsuccessful for some people, while the second seems to work.

I would like to know why and which one is best to choose in order to minimize potential import failures?

from PIL import Image # Fails for some ?! import Image 
+4
source share
2 answers

" import Image " works because PIL uses site-specific bindings to add its installation directory to the import path.

 [ me@oldserver ]$ cat /usr/lib/python2.4/site-packages/PIL.pth PIL 

The only situation I can think about is where " import Image " works, but " from PIL import Image " does not exist if the installation directory for PIL is outside the import path, but there is a .pth file that points to /some/install/path/PIL .

+7
source

referring to PIL Install

Step 1: Install Build Dependencies

 sudo apt-get build-dep python-imaging 

Step 2: symlink libraries

 sudo ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libjpeg.so /usr/lib/ sudo ln -s /usr/lib/`uname -i`-linux-gnu/libz.so /usr/lib/ 

Step 3: Install

 pip install PIL 
+3
source

Source: https://habr.com/ru/post/1384087/


All Articles