编程学习网 > 编程语言 > Python > Python如何安装第三方库?
2021
06-30

Python如何安装第三方库?


这篇文章主要介绍了Python安装第三方库的3种方法,本文讲解了通过setuptools来安装python模块、通过pip来安装python模块、直接从网上下载下可执行文件来安装三种方法,需要的朋友可以参考下:

【方法一】: 通过setuptools来安装python模块

首先下载 http://peak.telecommunity.com/dist/ez_setup.py

NOTE: 最好下载个setuptools,本人是15.2版本,里面包含了ez_setup

运行 python ez_setup.py


D:\work\installation\setuptools-15.2\setuptools-15.2>python ez_setup.py >1.txt
Extractinginc:\users\admini~1\appdata\local\temp\tmpbxikxf
Now workinginc:\users\admini~1\appdata\local\temp\tmpbxikxf\setuptools-15.2
Installing Setuptools
......
Copying setuptools-15.2-py2.7.eggto c:\python27\lib\site-packages
setuptools15.2isalready the active versionineasy-install.pth
Installing easy_install-script.py script to C:\Python27\Scripts
Installing easy_install.exe script to C:\Python27\Scripts
Installing easy_install-2.7-script.py script to C:\Python27\Scripts
Installing easy_install-2.7.exe script to C:\Python27\Scripts
  
  
Installed c:\python27\lib\site-packages\setuptools-15.2-py2.7.egg
Processing dependenciesforsetuptools==15.2
Finished processing dependenciesforsetuptools==15.2


运行 easy_install py


D:\work>easy_install py     #py 为第三方库文件
Searchingforpy
Best match: py1.4.26
Adding py1.4.26to easy-install.pthfile
  
Using c:\python27\lib\site-packages
Processing dependenciesforpy
Finished processing dependenciesforpy


【方法二】: 通过pip来安装python模块


安装 easy_install pip


D:\work>easy_install pip
Searchingforpip
Best match: pip6.1.1
Processing pip-6.1.1-py2.7.egg
pip6.1.1isalready the active versionineasy-install.pth
Installing pip-script.py script to C:\Python27\Scripts
Installing pip.exe script to C:\Python27\Scripts
Installing pip2.7-script.py script to C:\Python27\Scripts
Installing pip2.7.exescript to C:\Python27\Scripts
Installing pip2-script.py script to C:\Python27\Scripts
Installing pip2.exe script to C:\Python27\Scripts
  
Using c:\python27\lib\site-packages\pip-6.1.1-py2.7.egg
Processing dependenciesforpip
Finished processing dependenciesforpip


运行 pip install xlrd


Usage:  
 pip <command> [options]
  
Commands:
 install           Install packages.
 uninstall          Uninstall packages.
 freeze           Output installed packagesinrequirementsformat.
 list           Listinstalled packages.
 show            Show information about installed packages.
 search           Search PyPIforpackages.
 wheel            Build wheelsfromyour requirements.
 zip            DEPRECATED.Zipindividual packages.
 unzip            DEPRECATED. Unzip individual packages.
 help           Showhelpforcommands.
  
General Options:
 -h,--help        Showhelp.
 --isolated         Run pipinan isolated mode, ignoring
               environment variablesanduser configuration.
 -v,--verbose        Give more output. Optionisadditive,andcan be
               used up to3times.
 -V,--version        Show versionandexit.
 -q,--quiet         Give less output.
 --log <path>        Path to a verbose appending log.
 --proxy <proxy>       Specify a proxyinthe form
               [user:passwd@]proxy.server:port.
 --retries <retries>     Maximum number of retries each connection should
               attempt (default5times).
 --timeout <sec>      Setthe socket timeout (default15seconds).
 --exists-action <action>  Default action when a path already exists:
               (s)witch, (i)gnore, (w)ipe, (b)ackup.
 --trusted-host <hostname>  Mark this host as trusted, even though it does
               nothave validoranyHTTPS.
 --cert <path>        Path to alternate CA bundle.
 --client-cert <path>    Path to SSL client certificate, a singlefile
               containing the private keyandthe certificate
               inPEMformat.
 --cache-dir<dir>      Store the cache datain<dir>.
 --no-cache-dir      Disable the cache.
 --disable-pip-version-check
               Don't periodically check PyPI to determine
               whether a new version of pipisavailablefor
               download. Implied with--no-index.


【方法三】:直接从网上下载下可执行文件来安装.

比如说,去 >>> pythonlibs <<< 网站,提供了很多Python非官方包下载,二进制文件,下载安装方便.

以上就是“Python如何安装第三方库?”的详细内容,想学习更多Python教程请持续关注编程学习网!

扫码二维码 获取免费视频学习资料

Python编程学习

查 看2022高级编程视频教程免费获取