起因
需要在一台联网的计算机和一台不联网的计算机上安装 Python 包。
pygame 在线安装失败
在 CMD 命令行运行下列命令安装 pygame:
python -m pip install --user pygame
或 pip install pygame
超时安装失败!
离线安装 pygame
通过博文找到离线下载地址:https://pypi.org/project/pygame/#files
下载后通过以下命令安装:pip install pygame-***-win_amd64.whl
但尝试了几个以 win_amd64.whl 结尾的包均以失败告终。
通过博文了解到可通过 pip debug --verbose
命令查看 .whl 包的规范命名。
我安装的是 Python3.11,使用的是 win64 位系统,查看到的规范命名是:
Compatible tags: 39
cp311-cp311-win_amd64
相关规范名称的包在 pypi.org 上找不到!
后来在 GitHub 上找到了下载地址:https://github.com/pygame/pygame/releases
原来支持 Python3.11 的 pygame 上属于预览版:
https://github.com/pygame/pygame/releases/download/2.1.3.dev8/pygame-2.1.3.dev8-cp311-cp311-win_amd64.whl
使用以下命令离线安装成功:pip install pygame-2.1.3.dev8-cp311-cp311-win_amd64.whl
离线安装 matplotlib
然而在matplotlib官网和GitHub并未找到离线安装包,但找到一个非官方下载的站点:https://www.lfd.uci.edu/~gohlke/pythonlibs/
可以下载到兼容 Python3.11 的包,但不是最新版的 matplotlib。
安装 plotly
在plotly官网、Github、及上述离线下载站点均未找到离线安装包。
使用 pip --help
查看帮助,可使用 timeout 避免下载超时失败:
pip install plotly==5.11.0 --timeout 100
pip --help
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
inspect Inspect the python environment.
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.
index Inspect information available from package indexes.
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.
--debug Let unhandled exceptions propagate outside the main subroutine, instead of logging them
to stderr.
--isolated Run pip in an isolated mode, ignoring environment variables and user configuration.
--require-virtualenv Allow pip to only run in a virtual environment; exit with an error otherwise.
--python <python> Run pip with the specified Python interpreter.
-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.
--no-input Disable prompting for input.
--proxy <proxy> Specify a proxy in the form scheme://[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 PEM-encoded CA certificate bundle. If provided, overrides the default. See 'SSL
Certificate Verification' in pip documentation for more information.
--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.
--use-feature <feature> Enable new functionality, that may be backward incompatible.
--use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.
在线安装 plotly 过程中,使用 Everything 搜索,plotly*.whl
,查找到 Temp 文件夹下存在名称为 plotly-5.11.0-py2.py3-none-any.whl 的文件,在下载完成后安装前复制该文件(安装完成后该文件将自动删除)即可得到离线安装包。