在Python 3中安装PIL(Python Imaging Library)的推荐方法是使用Pillow库,因为Pillow是PIL的一个分支,并且支持Python 3。以下是安装Pillow的步骤:
1. 打开命令行工具(如Windows的命令提示符或macOS/Linux的终端)。
2. 输入以下命令来安装Pillow库:
```
pip install Pillow
如果你使用的是Anaconda环境,Pillow可能已经预装好了。
安装完成后,你可以通过以下代码测试Pillow是否安装成功:
```python
from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
如果上述代码没有报错,并且能够正常打开和旋转图片,那么Pillow安装就是成功的。
如果你在安装过程中遇到权限问题,可以尝试使用`--user`标志:
```
pip install --user Pillow
希望这能帮助你成功安装Pillow库!