使用pip安装python库的多种方式

yipeiwu_com6年前Python基础

操作系统 : CentOS7.5.1804_x64

Python 版本 : 3.6.8

1、使用pip在线安装

1.1 安装单个package

格式如下:

pip install SomePackage

示例如下:

比如:pip install scipy

或者指定版本安装:pip install scipy==1.3.0

1.2 安装多个package

示例如下:

pip install -r req.txt

req.txt 可以通过以下命令获取:

pip freeze > req.txt

1.3 在线安装的其它问题

1.3.1 代理问题

如果需要通过代理安装,可以使用如下格式:

pip --proxy=ip:port install SomePackage

1.3.2 pip源问题

如果pip源太慢,可以更换pip源,有以下两种方式:

方式一:通过修改参数临时修改pip源

比如使用阿里云的pip源:

pip install Sphinx -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

方式二:通过修改配置文件永久修改pip源

文件: ~/.pip/pip.conf

比如使用阿里云的pip源:

[admin@localhost .pip]$ cat ~/.pip/pip.conf
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
extra-index-url=http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
[admin@localhost .pip]$

也可以使用自建pip源,或者其它公开pip源,比如:

阿里云 http://mirrors.aliyun.com/pypi/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

2、从源码安装

示例如下:

git clone https://github.com/sphinx-doc/sphinx
cd sphinx
pip install .

3、从 whl 文件安装

格式如下:

pip install SomePackage.whl

本文github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2019/20190730_使用pip安装python库的几种方式.rst

总结

以上所述是小编给大家介绍的使用pip安装python库的多种方式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对【听图阁-专注于Python设计】网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

相关文章

python使用xpath中遇到:<Element a at 0x39a9a80>到底是什么?

前言 大家在学习python爬虫的过程中,会发现一个问题,语法我看完了,说的也很详细,我也认真看了,爬虫还是不会写,或者没有思路,所以我的所有文章都会从实例的角度来解析一些常见的问题和...

Python读写unicode文件的方法

本文实例讲述了Python读写unicode文件的方法。分享给大家供大家参考。具体实现方法如下: #coding=utf-8 import os import codecs d...

python aiohttp的使用详解

python aiohttp的使用详解

1.aiohttp的简单使用(配合asyncio模块) import asyncio,aiohttp async def fetch_async(url): print(url)...

python 实现tar文件压缩解压的实例详解

python 实现tar文件压缩解压的实例详解 压缩文件: import tarfile import os def tar(fname): t = tarfile.op...

python引用DLL文件的方法

本文实例讲述了python引用DLL文件的方法。分享给大家供大家参考。具体分析如下: 在python中调用dll文件中的接口比较简单,如我们有一个test.dll文件,内部定义如下:...