Tony Chen Tony Chen - 1 year ago 160
Bash Question

how to install PIL on python shell on OS X 10.9.5

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 -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.

Answer Source

You should run the pip command from a system terminal (BASH prompt), not from inside Python. Normally you would open /Applications/Utilities/, 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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download