1 安装来源
1.1 从requirements文件进行安装
pip install -r requirements.txt
1.2 从git进行安装
pip install -e git://git.example.com/MyProject#egg=MyProject
pip install -e git+http://git.example.com/MyProject#egg=MyProject
pip install -e git+https://git.example.com/MyProject#egg=MyProject
pip install -e git+ssh://git.example.com/MyProject#egg=MyProject
pip install -e git+git://git.example.com/MyProject#egg=MyProject
pip install -e git+file:///home/user/projects/MyProject#egg=MyProject
1.3 从从SVN进行安装
pip install -e svn+https://svn.example.com/MyProject#egg=MyProject
pip install -e svn+ssh://svn.example.com/MyProject#egg=MyProject
pip install -e svn+ssh://user@svn.example.com/MyProject#egg=MyProject
1.4 从Mercuria进行安装
pip install -e hg+http://hg.myproject.org/MyProject#egg=MyProject
pip install -e hg+https://hg.myproject.org/MyProject#egg=MyProject
pip install -e hg+ssh://hg.myproject.org/MyProject#egg=MyProject
pip install -e hg+file:///home/user/projects/MyProject#egg=MyProject
1.5 从Bazaar进行安装
pip install -e bzr+http://bzr.example.com/MyProject/trunk#egg=MyProject
pip install -e bzr+sftp://user@example.com/MyProject/trunk#egg=MyProject
pip install -e bzr+ssh://user@example.com/MyProject/trunk#egg=MyProject
pip install -e bzr+ftp://user@example.com/MyProject/trunk#egg=MyProject
pip install -e bzr+lp:MyProject#egg=MyProject
1.6 使用wheel文件安装
除了使用上面的方式联网进行安装外,还可以将安装包也就是wheel格式的文件,下载到本地,然后使用pip进行安装。比如我在PYPI上提前下载的pillow库的wheel文件,后缀名为whl。
可以取www.lfd.uci.edu/~gohlke/pyt…地址下载对应版本的安装包,以lxml为例,截图如下:
下载后安装命令如下:
pip install lxml-4.7.1-cp39-cp39-win amd64.whl
2 安装不同的版本
这里以Django为例进行展示
2.1 安装最新的版本
pip install Django
2.2 安装指定的版本
pip install Django==2.0
2.3 安装最小的版本
pip install Django>=2.0
3 设置镜像源
3.1 常见的镜像源
清华: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/
3.2 临时性的镜像源
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Django
3.3 永久性的设置镜像源
3.3.1 设置单一的镜像源
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\xx\pip,新建文件pip.ini。内容如上所示
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)内容如上所示
3.3.2 设置多个镜像源
[global]
timeout=40
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
extra-index-url=
https://mirrors.aliyun.com/pypi/simple/
https://pypi.douban.com/simple
https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host=
pypi.tuna.tsinghua.edu.cn
mirrors.aliyun.com
pypi.douban.com
pypi.mirrors.ustc.edu.cn
proxy_servers:
http: https://xxx.xxx.x.xx:8080
https: https://xxx.xxx.x.xx:8080
ssl_verify: false