0

I am new to Python. I try to install PIL using Python 3.5.2 shell. I input pip install PIL into python interpreter first. It didn't work and showed me this: SyntaxError: invalid syntax.

Then I searched online and tried this: pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL. Still a syntax error.

Finally I tried this: install PIL and didn't work either.

I wonder if a shell command is different with the terminal command? I am using OS X 10.9.5 at the moment and if I using terminal to write python it will be Python 2.7.X and because it's related to some system files so I can't change it. I want to ask how can I install PIL or other modules using a Python shell?

This question is different with other questions related to "How to install PIL". I am trying to ask how to use Python 3.5 shell to install PIL. If I install PIL using terminal command then it will be installed into my system default python, which is Python 2.7.X.

Tony Chen
  • 183
  • 1
  • 16
  • Possible duplicate of [Installing PIL with pip](http://stackoverflow.com/questions/20060096/installing-pil-with-pip) – Christian Ternus Aug 24 '16 at 23:10
  • I think somebody answered your question [here](http://stackoverflow.com/questions/20060096/installing-pil-with-pip) – Saman Aug 24 '16 at 23:10
  • Also [here](http://stackoverflow.com/questions/35929306/how-to-install-pil-to-python-3-5-on-a-mac/35929343#35929343) – Nathaniel Ford Aug 24 '16 at 23:12
  • Those questions deal with installing PIL in general; this question is about how to use pip to install PIL in Python 3.5 when pip has been installed for Python 2.7. – Matthias Fripp Aug 24 '16 at 23:28
  • How did you install your copies of Python 2.7 and 3.5? Do you only use Python 3.5, or also 2.7? You should probably get pip working with Python 3.5 instead of 2.7, but the best way to do that that depends on your answers to those questions. – Matthias Fripp Aug 24 '16 at 23:38
  • I just download it from [link](http://python.org) . I thought I saw a article about updating the Python on OS X but in the end of the article it says updating by substitute the default version of Python is dangerous because some system files are python files. So I end up using Python shell instead. – Tony Chen Aug 25 '16 at 21:07

2 Answers2

1

You should run the pip command from a system terminal (BASH prompt), not from inside Python. Normally you would open /Applications/Utilities/Terminal.app, and then type pip install PIL. If that installs packages for Python 2.7 instead of 3.5, you could try this instead: python3 $(which pip) install PIL.

Or from within Python 3.5 you could try this (from Installing python module within code):

import pip
pip.main(['install', 'PIL'])

A longer-term solution would be to install pip to work with Python 3.5 instead of 2.7. To do that, you would run these commands from the system terminal:

curl --remote-name https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py

Then pip install PIL should install PIL in your 3.5 installation.

Community
  • 1
  • 1
Matthias Fripp
  • 17,670
  • 5
  • 28
  • 45
  • You should consider [Pillow](https://pillow.readthedocs.io) instead of the "old" PIL library. – Laurent LAPORTE Aug 25 '16 at 21:02
  • It showed me this error: "Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL" so I tried pillow and it works. Thank you both of you! and I appreciate your specific answer! @mfripp – Tony Chen Aug 25 '16 at 21:14
1
pip install pillow

pillow is a wrapper to an old PIL package and it works like a charm.

turkus
  • 4,637
  • 2
  • 24
  • 28