Python第三方库安装
安装第三方库可以有这几种方法:
-
PyPl: Python Package Index 第三方库的社区,用于搜索并了解自己所需要的第三方库。
- 第1步:在pypi.org搜索 blockchain
- 第2步:挑选适合开发目标的第三方库作为基础
- 第3步:完成自己需要的功能
-
pip
命令是主要的第三方库安装方法- pip安装会遇到的问题之一就是下载速度慢,这里可能就需要要用到镜像地址。
- 如果要了解更多pip的用法,可以
pip -h
查看pip帮助信息
-
UCI 页面的“补丁”安装方法
- 适用于某些第三方库pip下载后,但无法安装的情况,这可能是因为第三方库只提供了源代码,需要编译再安装。如果操作系统没有编译环境,可以直接在UCI下载编译后的版本用于安装。
-
Anaconda集成开发工具及安装方法,anaconda自带800+第三方库安装
pip镜像地址
如果按照下面的代码,直接下载,速度非常慢,可能会下载失败
python -m pip install --upgrade pip
pip install pyinstaller
pip install jieba
这时候可以改用镜像地址,在原来的代码后面加上-i https://pypi.tuna.tsinghua.edu.cn/simple
就可以飞速下载了!
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install jieba -i https://pypi.tuna.tsinghua.edu.cn/simple
这里是用镜像地址的下载速度,速度为 6.8 MB/s
pip批量安装第三方库
# BatchInstall.py
import os
# 填需要安装的第三方库
libs = {"numpy","matplotlib","pillow","sklearn","requsets","jieba","beautifulsoup4","wheel","networkx","sympy","pyinstaller","django","flask","werobot","pyqt5","pandas","pyopeng1","pypdf2","docopt","pygame"}
try:
for lib in libs:
os.system("pip install " + lib + " -i https://pypi.tuna.tsinghua.edu.cn/simple")
print("Successful")
except:
print("Failed Somehow")
其他可以替换的国内的镜像网站:
清华: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/
pip -h 查看pip帮助信息
pip -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.
config Manage local and global configuration.
search Search PyPI for packages.
cache Inspect and manage pip's wheel cache.
wheel Build wheels from your requirements.
hash Compute hashes of package archives.
completion A helper command used for command completion.
debug Show information useful for debugging.
help Show help for commands.
General Options:
-h, --help Show help.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
-V, --version Show version and exit.
-q, --quiet Give less output. Option is additive, and can be used up to 3 times (corresponding to
WARNING, ERROR, and CRITICAL logging levels).
--log <path> Path to a verbose appending log.
--proxy <proxy> Specify a proxy in the form [user:passwd@]proxy.server:port.
--retries <retries> Maximum number of retries each connection should attempt (default 5 times).
--timeout <sec> Set the socket timeout (default 15 seconds).
--exists-action <action> Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup,
(a)bort.
--trusted-host <hostname> Mark this host or host:port pair as trusted, even though it does not have valid or any
HTTPS.
--cert <path> Path to alternate CA bundle.
--client-cert <path> Path to SSL client certificate, a single file containing the private key and the
certificate in PEM format.
--cache-dir <dir> Store the cache data in <dir>.
--no-cache-dir Disable the cache.
--disable-pip-version-check
Don't periodically check PyPI to determine whether a new version of pip is available for
download. Implied with --no-index.
--no-color Suppress colored output
--no-python-version-warning
Silence deprecation warnings for upcoming unsupported Pythons.
参考内容:
https://blog.csdn.net/qq_37816095/article/details/104366669
https://www.cnblogs.com/songzhixue/p/11296720.html