“Python第三方库的安装”的版本间的差异

来自CloudWiki
跳转至: 导航搜索
第67行: 第67行:
 
pygame (1.9.3)
 
pygame (1.9.3)
 
setuptools (28.8.0)</nowiki>
 
setuptools (28.8.0)</nowiki>
 +
 +
===升级已安装的库===
 +
pip install --upgrade 要升级的包名
  
 
===卸载已安装的库===
 
===卸载已安装的库===

2020年12月21日 (一) 03:27的版本

pip工具安装

  • 最常用且最高效的python第三方安装工具是采用pip工具安装。pip是python官方提供并维护的在线第三方库安装工具。对于同时安装python2和python3环境的系统,建议采用pip3命令专门为Python3版本安装第3方库。
  • pip是python内置命令,需要通过命令行执行。执行pip -h将列出她常用的字命令。
C:\Users\thinkpad>pip3 -h

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

[windows下面安装Python和pip终极教程 http://blog.csdn.net/lengqi0101/article/details/61921399]

[pip安装python库总是下载超时,有什么解决方法吗? http://segmentfault.com/q/1010000000162410]

安装库

  • 安装一个库的命令,格式如下:
pip3 install <拟安装库名>
  • 例子:
C:\Users\thinkpad>pip3 install pygame
Collecting pygame
  Downloading pygame-1.9.3-cp36-cp36m-win32.whl (4.0MB)
    5% |█▊                              | 215kB 28kB/s eta 0:02:11

如果系统中安装了多个python版本,可使用下列命令指定安装的python版本,其中的参数t的值可以使用import sys;print(sys.path)来获取

pip3 install -t C:\\Users\\thinkpad\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages xlrd

安装库时添加国内源

pip3 install pymysql -i 国内的源

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

豆瓣:http://pypi.douban.com/simple/

安装时指定版本

pip3 install <拟安装库名>==<版本号>

例:

pip3 install markdown==2.6.8

查看已安装的库

  • pip3 list
C:\Users\thinkpad>pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
pip (9.0.1)
pygame (1.9.3)
setuptools (28.8.0)

升级已安装的库

pip install --upgrade 要升级的包名

卸载已安装的库

  • pip3 uninstall pygame
 Proceed (y/n)? y
 Successfully uninstalled pygame-1.9.3


自定义安装

文件安装

当目标机器处于离线环境,无法使用pip在线安装时,或者某些第三方库仅提供源代码,通过pip下载文件后无法在Windows系统编译安装时,可从下列网站下载对应的第三方库,并拷贝至目标机上。

https://www.lfd.uci.edu/~gohlke/pythonlibs/

这是美国加州大学尔湾分校为了解决这类第三方库的安装问题,提供的一个网页,帮助Python用户获得Windows可直接安装的第三方库文件。

下载网址

https://www.lfd.uci.edu/~gohlke/pythonlibs

安装方法

pip install 完整路径名.whl