编辑:这不是python脱机软件包安装的重复,因为答案要求存在'pip'。我的前提是当" pip"不可用时。
我的python脚本取决于这个github库。我需要创建一个包括此依赖性的自给自足的Tarball,并且可以在我的生产服务器上提取和运行,该服务器确实无法访问Internet或Pip 。但是我有Python 2.6.6/Python 2.7
我在本地计算机(具有互联网(上创建了一个Virtualenv,并使用PIP安装了依赖性。PIP下载了依赖的库。我获得了
的要求。pip freeze > requirements.txt
现在我使用
下载了这些要求pip download -r requirements.txt
下载的内容是
decorator-4.4.0-py2.py3-none-any.whl
jsonpath-rw-1.4.0.tar.gz
jsonpath_rw_ext-1.2.0-py2.py3-none-any.whl
pbr-5.2.0-py2.py3-none-any.whl
ply-3.11-py2.py3-none-any.whl
six-1.12.0-py2.py3-none-any.whl
我还创建了一个setup.py,其中 install_requires
具有所有要求的内容。
import setuptools
setuptools.setup(
name="Resizing Automation Validation Script",
packages=setuptools.find_packages(),
install_requires=['ply','pbr','six','decorator','jsonpath-rw','jsonpath-rw-ext'],
classifiers=[
"Programming Language :: Python :: 2.6.6",
"Operating System :: OS Independent",
],
)
我尝试运行以下命令来安装这些脚本(PIP不可用(
python setup.py develop --always-unzip --allow-hosts=None --find-links=/path/to/download/dir
注意:以上命令在本地创建的virtualenv上工作。
但是它在服务器上(无互联网(失败,错误
running develop
running egg_info
creating Resizing_Automation_Validation_Script.egg-info
writing requirements to Resizing_Automation_Validation_Script.egg-info/requires.txt
writing Resizing_Automation_Validation_Script.egg-info/PKG-INFO
writing top-level names to Resizing_Automation_Validation_Script.egg-info/top_level.txt
writing dependency_links to Resizing_Automation_Validation_Script.egg-info/dependency_links.txt
writing manifest file 'Resizing_Automation_Validation_Script.egg-info/SOURCES.txt'
reading manifest file 'Resizing_Automation_Validation_Script.egg-info/SOURCES.txt'
writing manifest file 'Resizing_Automation_Validation_Script.egg-info/SOURCES.txt'
running build_ext
Creating /deployeruser/.local/lib/python2.7/site-packages/Resizing-Automation-Validation-Script.egg-link (link to .)
Adding Resizing-Automation-Validation-Script 1.0.0 to easy-install.pth file
Installed /deployeruser/tmp
Processing dependencies for Resizing-Automation-Validation-Script==1.0.0
Searching for jsonpath-rw-ext
Link to https://pypi.python.org/simple/jsonpath-rw-ext/ ***BLOCKED*** by --allow-hosts
Couldn't find index page for 'jsonpath-rw-ext' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Link to https://pypi.python.org/simple/ ***BLOCKED*** by --allow-hosts
No local packages or download links found for jsonpath-rw-ext
使用pip效果很好
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
但是,如果没有PIP
没有PIP安装需要您直接从Tarball存档中安装。所以,
- 首先,获取依赖项的所有TARBALL档案
- 将Tarballs转移到依赖机器
- 将所有TARBALLS提取到temp文件夹
- 使用'python setup.py install -user' 安装
- 运行程序:(
详细信息:
- 使用
pip freeze > requirements.txt
生成需求。 从您的Python环境中获取Tarballs
- CD到您的下载文件夹
运行
pip download -r ../requirements.txt --no-binary :all:
。将所有要求下载为tar.gz存档到当前目录记住下载目标机器中缺少的所有内部依赖关系。我还需要下载python 2.6.6
的setuptools-0.6c9
将下载文件夹转移到生产机器(无互联网和PIP(
CD下载文件夹并运行以下命令,将依赖项安装到当前活动的python。
install_tarball_python.sh [tar.gz-file]
#!/bin/bash
# Script: install_tarball_python
# takes the tar.gz dependency as arg
# creates a temp directory and extracts the archive in it.
# 'cd's into the extracted archive and runs 'python setup.py install'
# 'cd's back to the current directory and removes the temp containing the decompressed archive
if [ $# -lt 1 ]; then
echo "Usage: install_tarball_python <package.tar.gz>"
exit 1
fi
pushd . && mkdir temp && tar zxf $1 -C temp && cd temp && cd * && python setup.py install --user&& popd && rm -rf temp
- 运行您的Python脚本。