python中安装第三方模块

时间:2021-05-30 11:38:51

Python有两个封装了setuptools的包管理工具:easy_installpip。目前官方推荐使用pip

现在,让我们来安装一个第三方库——Python Imaging Library,这是Python下非常强大的处理图像的工具库。一般来说,第三方库都会在Python官方的pypi.python.org网站注册,要安装一个第三方库,必须先知道该库的名称,可以在官网或者pypi上搜索,比如Python Imaging Library的名称叫PIL,因此,安装Python Imaging Library的命令就是:

pip install PIL

出现如下问题:

Traceback (most recent call last):
File “/usr/bin/pip-python”, line , in <module>
from pkg_resources import load_entry_point
File “build/bdist.linux-x86_64/egg/pkg_resources.py”, line , in <module>
File “build/bdist.linux-x86_64/egg/pkg_resources.py”, line , in _build_master
File “build/bdist.linux-x86_64/egg/pkg_resources.py”, line , in require
File “build/bdist.linux-x86_64/egg/pkg_resources.py”, line , in resolve
pkg_resources.DistributionNotFound: pip==0.8

出现上述错误主要是由于python的版本太过老了,需要下载最新版本的setuptools

无奈之下,只好去安装easy_install并安装。

easy_install PIL
--------------------------------------------------------------------
PIL 1.1. SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.
platform linux2 2.7. (default, Jul , ::)
[GCC 4.8.]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script. To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
Adding PIL 1.1. to easy-install.pth file
Installing pilprint.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing pilconvert.py script to /usr/local/bin
Installing pildriver.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin Installed /usr/local/lib/python2./site-packages/PIL-1.1.-py2.-linux-i686.egg
Processing dependencies for PIL
Finished processing dependencies for PIL