一.在线安装
让 python pip 使用国内镜像源
国内镜像源:
清华: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/
注意:新版 Ubuntu 要求使用https源。
例如:pip3 install -i https://pypi.doubanio.com/simple/ 包名
临时使用:#
可以在使用pip的时候加参数 -i https://pypi.tuna.tsinghua.edu.cn/simple
例如:pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider
,这样就会从清华的镜像去安装pyspider库。
永久修改,一劳永逸:#
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在 %userprofile% 目录中创建一个 pip目录,再新建文件 pip.ini。(例如:C:\Users\WQP\pip\pip.ini)内容同上。
二.离线安装
方法1:
win32常用:
import pip;
print(pip.pep425tags.get_supported())
amd64常用:
import pip._internal
print(pip._internal.pep425tags.get_supported())
或
import pip._internal.pep425tags
或
import wheel.pep425tags as w
方法2:
import wheel as w
w..pep425tags.get_supported()
方法3:
使用源码包安装 (推荐)
例: https://pypi.org/project/simplejson/#filesx
下载.tar.gz文件, 解压缩, 运行python setup.py install 进行安装
豆瓣源:https://pypi.doubanio.com/simple/
方法4:
python -m pip debug --verbose
打印可以看出支持的版本清单
(base) C:\Users\25208>python -m pip debug --verbose
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 21.0.1 from C:\ProgramData\Anaconda3\lib\site-packages\pip (python 3.8)
sys.version: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
sys.executable: C:\ProgramData\Anaconda3\python.exe
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: cp936
sys.platform: win32
sys.implementation:
name: cpython
'cert' config value: Not specified
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\certifi\cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
appdirs==1.4.4
CacheControl==0.12.6
colorama==0.4.4
contextlib2==0.6.0.post1 (Unable to locate actual module version, using vendor.txt specified version)
distlib==0.3.1
distro==1.5.0 (Unable to locate actual module version, using vendor.txt specified version)
html5lib==1.1
msgpack==1.0.2 (Unable to locate actual module version, using vendor.txt specified version)
packaging==20.9
pep517==0.9.1
progress==1.5
pyparsing==2.4.7
requests==2.25.1
certifi==2020.12.05
chardet==4.0.0
idna==2.10
urllib3==1.26.2
resolvelib==0.5.4
retrying==1.3.3 (Unable to locate actual module version, using vendor.txt specified version)
setuptools==44.0.0 (Unable to locate actual module version, using vendor.txt specified version)
six==1.15.0
toml==0.10.2
webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 30
cp38-cp38-win_amd64
cp38-abi3-win_amd64
cp38-none-win_amd64
cp37-abi3-win_amd64
cp36-abi3-win_amd64
cp35-abi3-win_amd64
cp34-abi3-win_amd64
cp33-abi3-win_amd64
cp32-abi3-win_amd64
py38-none-win_amd64
py3-none-win_amd64
py37-none-win_amd64
py36-none-win_amd64
py35-none-win_amd64
py34-none-win_amd64
py33-none-win_amd64
py32-none-win_amd64
py31-none-win_amd64
py30-none-win_amd64
cp38-none-any
py38-none-any
py3-none-any
py37-none-any
py36-none-any
py35-none-any
py34-none-any
py33-none-any
py32-none-any
py31-none-any
py30-none-any
操作:
1. pip download package1
2.pip install package1