从pypi下载python包及其依赖项以离线安装到另一台机器的最佳方法是什么?使用pip或easy_install是否有简单的方法来做到这一点?我试图在一个没有连接到互联网的FreeBSD盒子上安装请求库。
当前回答
在可以访问internet的系统上
pip download命令允许你下载软件包而不安装它们:
pip download -r requirements.txt
(在pip的以前版本中,这被拼写为pip install——download -r requirements.txt。)
在无法访问internet的系统上
然后你可以使用
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
在不访问网络的情况下安装那些下载的模块。
其他回答
从Pypi下载wheel文件(例如ddb -0.5.0-py3-none-any.whl)
pip install dlb-0.5.0-py3-none-any.whl
如果您想离线安装python库及其依赖项,请在具有相同操作系统、网络连接并安装python的机器上完成以下步骤:
1)创建一个包含类似内容的requirements.txt文件(注意-这些是你希望下载的库):
Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0
创建需求文件的一个选项是使用pip freeze > requirements.txt。这将列出环境中的所有库。然后您可以进入requirements.txt,删除不需要的文件。
2)执行命令mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse,将lib及其依赖项下载到目录wheelhouse
3)拷贝requirements.txt到wheelhouse目录
4)用tar -zcf wheelhouse.tar.gz归档wheelhouse到wheelhouse.tar.gz
然后上传wheelhouse.tar.gz到你的目标机器:
1)执行tar -zxf wheelhouse.tar.gz解压文件
2)执行pip install -r wheelhouse/requirements.txt——no-index——find-links wheelhouse安装lib及其依赖项
作为一个继续@chaokunyang的回答,我想把我写的脚本放在这里:
编写一个“requirements.txt”文件,指定想要打包的库。 创建一个包含所有库的tar文件(参见Packer脚本)。 将创建的tar文件放到目标计算机中并解压缩它。 运行安装程序脚本(它也被打包到tar文件中)。
“让”文件
docker==4.4.0
包装端:文件名:"create-offline-python3.6-dependencies-repository.sh"
#!/usr/bin/env bash
# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983
LIBRARIES_DIR="python3.6-wheelhouse"
if [ -d ${LIBRARIES_DIR} ]; then
rm -rf ${LIBRARIES_DIR}/*
else
mkdir ${LIBRARIES_DIR}
fi
pip download -r requirements.txt -d ${LIBRARIES_DIR}
files_to_add=("requirements.txt" "install-python-libraries-offline.sh")
for file in "${files_to_add[@]}"; do
echo "Adding file ${file}"
cp "$file" ${LIBRARIES_DIR}
done
tar -cf ${LIBRARIES_DIR}.tar ${LIBRARIES_DIR}
安装端:文件名:"install-python-libraries-offline.sh"
#!/usr/bin/env bash
# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983
# This file should run during the installation process from inside the libraries directory, after it was untared:
# pythonX-wheelhouse.tar -> untar -> pythonX-wheelhouse
# |
# |--requirements.txt
# |--install-python-libraries-offline.sh
pip3 install -r requirements.txt --no-index --find-links .
在可以访问internet的系统上
pip download命令允许你下载软件包而不安装它们:
pip download -r requirements.txt
(在pip的以前版本中,这被拼写为pip install——download -r requirements.txt。)
在无法访问internet的系统上
然后你可以使用
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
在不访问网络的情况下安装那些下载的模块。
对于Pip 8.1.2,您可以使用Pip download -r request .txt将包下载到您的本地机器。
推荐文章
- 证书验证失败:无法获得本地颁发者证书
- 当使用pip3安装包时,“Python中的ssl模块不可用”
- 无法切换Python与pyenv
- Python if not == vs if !=
- 如何从scikit-learn决策树中提取决策规则?
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 将旋转的xtick标签与各自的xtick对齐
- 为什么元组可以包含可变项?
- 如何合并字典的字典?
- 如何创建类属性?
- 不区分大小写的“in”
- 在Python中获取迭代器中的元素个数
- 解析日期字符串并更改格式
- 使用try和。Python中的if
- 如何在Python中获得所有直接子目录