How to install pillow for python3

Hi!

I used the PIL library with python 2.x for a long time.
Now I am shifting all my python code to python3. Unfortunately I am not able to get the pillow package installed on my dietpi-machine.

Did anyone suceed on that?

When running “pip install pillow -v --no-cache-dir” I get the following error messages:

ERROR: Failed building wheel for pillow

and later:

ERROR: Command “/usr/bin/python -u -c ‘import setuptools, tokenize;file=’”’"’/tmp/pip-install-ZNfXJ2/pillow/setup.py’"’"’;f=getattr(tokenize, ‘"’"‘open’"’"’, open)(file);code=f.read().replace(’"’"’\r\n’"’"’, ‘"’"’\n’"’"’);f.close();exec(compile(code, file, ‘"’"‘exec’"’"’))’ install --record /tmp/pip-record-PY96iM/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-ZNfXJ2/pillow/


Any help appreciated.

Best regards,
Olaf

dietpiOK
Try to use the php3 command and install the setuptools and tokenize modules first:

pip3 install setuptools
pip3 install tokenize
pip3 install pillow

The “Failed building wheel” errors can be ignored btw. Those are not required, but if you want to get rid of the error message:

pip3 install wheel

there is no pip3 command and “apt-get install pip3” will not work…

apt-get install python3-pip tells me that it is already installed and I can find “pip”, “pip2” and “pip2.7” on my raspi.

setuptools are also installed and when trying to install “tokenize” I can see the following:

root@raspi:~# pip install tokenize
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won’t be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting tokenize
ERROR: Could not find a version that satisfies the requirement tokenize (from versions: none)
ERROR: No matching distribution found for tokenize

Any idea?

dietpiOK
Did you even install PIP for Python3 then? G_AGI python3-pip

root@raspi:~# G_AGI python3-pip
[ OK ] Root access verified.
[ INFO ] APT installation for: python3-pip, please wait…
[ OK ] G_AGI python3-pip

seems so…

Very strange, the pip3 binary is definitely part of that package. Can you run: dpkg -L python3-pip

root@raspi:~# dpkg -L python3-pip
/.
/usr
/usr/bin
/usr/bin/pip3
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/pip
/usr/lib/python3/dist-packages/pip/init.py
/usr/lib/python3/dist-packages/pip/main.py
/usr/lib/python3/dist-packages/pip/_vendor
/usr/lib/python3/dist-packages/pip/_vendor/init.py
/usr/lib/python3/dist-packages/pip/basecommand.py
/usr/lib/python3/dist-packages/pip/baseparser.py
/usr/lib/python3/dist-packages/pip/cmdoptions.py
/usr/lib/python3/dist-packages/pip/commands
/usr/lib/python3/dist-packages/pip/commands/init.py
/usr/lib/python3/dist-packages/pip/commands/check.py
/usr/lib/python3/dist-packages/pip/commands/completion.py
/usr/lib/python3/dist-packages/pip/commands/download.py
/usr/lib/python3/dist-packages/pip/commands/freeze.py
/usr/lib/python3/dist-packages/pip/commands/hash.py
/usr/lib/python3/dist-packages/pip/commands/help.py
/usr/lib/python3/dist-packages/pip/commands/install.py
/usr/lib/python3/dist-packages/pip/commands/list.py
/usr/lib/python3/dist-packages/pip/commands/search.py
/usr/lib/python3/dist-packages/pip/commands/show.py
/usr/lib/python3/dist-packages/pip/commands/uninstall.py
/usr/lib/python3/dist-packages/pip/commands/wheel.py
/usr/lib/python3/dist-packages/pip/compat
/usr/lib/python3/dist-packages/pip/compat/init.py
/usr/lib/python3/dist-packages/pip/compat/dictconfig.py
/usr/lib/python3/dist-packages/pip/download.py
/usr/lib/python3/dist-packages/pip/exceptions.py
/usr/lib/python3/dist-packages/pip/index.py
/usr/lib/python3/dist-packages/pip/locations.py
/usr/lib/python3/dist-packages/pip/models
/usr/lib/python3/dist-packages/pip/models/init.py
/usr/lib/python3/dist-packages/pip/models/index.py
/usr/lib/python3/dist-packages/pip/operations
/usr/lib/python3/dist-packages/pip/operations/init.py
/usr/lib/python3/dist-packages/pip/operations/check.py
/usr/lib/python3/dist-packages/pip/operations/freeze.py
/usr/lib/python3/dist-packages/pip/pep425tags.py
/usr/lib/python3/dist-packages/pip/req
/usr/lib/python3/dist-packages/pip/req/init.py
/usr/lib/python3/dist-packages/pip/req/req_file.py
/usr/lib/python3/dist-packages/pip/req/req_install.py
/usr/lib/python3/dist-packages/pip/req/req_set.py
/usr/lib/python3/dist-packages/pip/req/req_uninstall.py
/usr/lib/python3/dist-packages/pip/status_codes.py
/usr/lib/python3/dist-packages/pip/utils
/usr/lib/python3/dist-packages/pip/utils/init.py
/usr/lib/python3/dist-packages/pip/utils/appdirs.py
/usr/lib/python3/dist-packages/pip/utils/build.py
/usr/lib/python3/dist-packages/pip/utils/deprecation.py
/usr/lib/python3/dist-packages/pip/utils/encoding.py
/usr/lib/python3/dist-packages/pip/utils/filesystem.py
/usr/lib/python3/dist-packages/pip/utils/glibc.py
/usr/lib/python3/dist-packages/pip/utils/hashes.py
/usr/lib/python3/dist-packages/pip/utils/logging.py
/usr/lib/python3/dist-packages/pip/utils/outdated.py
/usr/lib/python3/dist-packages/pip/utils/packaging.py
/usr/lib/python3/dist-packages/pip/utils/setuptools_build.py
/usr/lib/python3/dist-packages/pip/utils/ui.py
/usr/lib/python3/dist-packages/pip/vcs
/usr/lib/python3/dist-packages/pip/vcs/init.py
/usr/lib/python3/dist-packages/pip/vcs/bazaar.py
/usr/lib/python3/dist-packages/pip/vcs/git.py
/usr/lib/python3/dist-packages/pip/vcs/mercurial.py
/usr/lib/python3/dist-packages/pip/vcs/subversion.py
/usr/lib/python3/dist-packages/pip/wheel.py
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/PKG-INFO
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/dependency_links.txt
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/entry_points.txt
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/not-zip-safe
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/requires.txt
/usr/lib/python3/dist-packages/pip-9.0.1.egg-info/top_level.txt
/usr/share
/usr/share/doc
/usr/share/doc/python3-pip
/usr/share/doc/python3-pip/changelog.Debian.gz
/usr/share/doc/python3-pip/changelog.gz
/usr/share/doc/python3-pip/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/pip3.1.gz

From /usr/bin I cannot start pip3 command. There is only a pip2 command.

How can I uninstall and reinstall pip3 or python?

i uninstalled and reinstalled python pin with the dietpi-software tool.
Now I can use pip 3 command but I am still not able to install pillow :frowning:

Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-build-g3b5ble8/pillow/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-ljxmuks_-record/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-build-g3b5ble8/pillow/

Any advise?

dietpiOK
Try to update/install the mentioned modules first: pip3 install setuptools tokenize

pip3 install setuptools worked perfectly, but:

root@raspi:~# pip3 install tokenize
Collecting tokenize
Could not find a version that satisfies the requirement tokenize (from versions: )
No matching distribution found for tokenize


What does that mean?

dietpiOK
Ah the modules is named “tokenizer”: pip3 install tokenizer
You might also need to install apt install python3-dev which is somehow missing when dietpi-software installs python3-pip.

Thanks, MichIng, I just did not see that typo.

Unfortunately installing pillow still does not work:

Command “/usr/bin/python3 -u -c “import setuptools, tokenize;file=’/tmp/pip-build-_8lazntv/pillow/setup.py’;f=getattr(tokenize, ‘open’, open)(file);code=f.read().replace(’\r\n’, ‘\n’);f.close();exec(compile(code, file, ‘exec’))” install --record /tmp/pip-yqukurd1-record/install-record.txt --single-version-externally-managed --compile” failed with error code 1 in /tmp/pip-build-_8lazntv/pillow/

root@raspi:~# pip3 install tokenizer
Requirement already satisfied: tokenizer in /usr/local/lib/python3.5/dist-packages

dietpiOK
You installed apt install python3-dev?

Yes, it is installed.

dietpiOK
Can you please paste the full output of pip3 install pillow? Perhaps some previous lines give a hint what is missing, e.g. some other dev or library package.

E.g.: https://stackoverflow.com/questions/39179948/how-do-i-install-pil-pillow-for-python-3-6

  • zlib required as long as you do not exclude it via command option.
  • The last error exactly matches yours (besides Windows style file paths) but the lines before clearly state that zlib is expected.

Also see: https://stackoverflow.com/questions/34631806/fail-during-installation-of-pillow-python-module-in-linux
Besides checking for and in case install missing libs/-dev packages, the suggestion is to update pip via pip :slight_smile::

pip3 install -U pip
hash -r # Required to reload the $PATH variable with the new pip3 binary

Issue is solved!

Thanks Dan, for your support.
I had tp update pip3… Now everything works and pillow is running.

Great that it worked. Made me play around a bid with pip/pip3 and it works quite handy in combination with APT packages. If you install modules via pip, the ones from the APT packages are even removed, so only the new version will stay in place, thus no data overhead :+1:. However of course bad if some own python project requires a specific version, however easy to achieve with pip as well, much more flexible than APT.