0

I used sudo pip3 to install Pillow in Python 3.5 (without sudo it will prompt PermissonError) and it said

Requirement already satisfied (use --upgrade to upgrade): Pillow in /usr/local/lib/python3.5/dist-packages

But when I tried to use it in the Program. It shows:

File "./level7.py", line 4, in <module>
  from Pillow import Image
ImportError: No module named 'Pillow'

My first few lines in my program are:

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from Pillow import Image

Besides, I found that in /home/-uname/.local/lib file, there is a Python2.7 file, but no Python3.5.

What's the relation between /usr/local and /home/-uname/.local? And how to fix this problem?

MattDMo
  • 100,794
  • 21
  • 241
  • 231
Da Chen
  • 33
  • 6
  • Yes , I use `sudo` with `pip3`. – Da Chen Sep 18 '16 at 01:49
  • 3
    If you look at the [documentation](http://pillow.readthedocs.io/en/3.3.x/handbook/tutorial.html) for Pillow, you will see how you are actually supposed to import it: `from PIL import Image` – idjaw Sep 18 '16 at 01:51
  • @idjaw, please turn your comment into an answer so that it can be accepted as the correct answer to this question – Seth Difley Sep 18 '16 at 01:55
  • 2
    As a side note, @DaChen, please look into using virtual environments `python3 -m venv venv` `source venv/bin/activate` `pip install Pillow` `python` `from PIL import Image` https://docs.python.org/3/library/venv.html – Seth Difley Sep 18 '16 at 01:58
  • 1
    @DaChen I would take the advice that just Seth Difley suggested. Virtual Environments keep your environment clean and contained. Here is the [doc](https://docs.python.org/3/library/venv.html) – idjaw Sep 18 '16 at 02:04
  • @SethDifley I'll try it. Thanks a lot. – Da Chen Sep 18 '16 at 02:10
  • @DaChen I asked because it looked like you were using `sudo` with `pip3` but that is bad practice in my opinion. – edwinksl Sep 18 '16 at 03:10

1 Answers1

2

Based off of the documentation for Pillow, you are actually supposed to import it as:

from PIL import Image
idjaw
  • 25,487
  • 7
  • 64
  • 83