问题
Edit: This is not a duplicate of Python offline package installation as the answer require 'pip' to be present. My premise is when 'pip' is not available.
My python script depends on this Github library. I need to create a self-sufficient tarball that includes this dependency and I can extract and run on my Production server, that does not have access to internet or pip. However I have Python 2.6.6/Python 2.7
I have created a virtualenv on my local machine (which has internet) and installed above dependency using pip. pip downloaded the dependent libraries. I obtained the requirements.txt with
pip freeze > requirements.txt
Now I downloaded these requirements using
pip download -r requirements.txt
Downloaded contents are
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
I also created a setup.py with install_requires
having all the contents of the requirements.txt (followed from this Python offline package installation)
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",
],
)
I tried running following command to install these scripts (pip is not available)
python setup.py develop --always-unzip --allow-hosts=None --find-links=/path/to/download/dir
Note: The above command works on a freshly created virtualenv in local.
But it on server(without internet) it fails with error
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
With pip it works fine
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
However, how do I make it work without pip
回答1:
Installing without pip requires you to install from the tarball archive directly. So,
- First, get all the tarball archives for the dependencies
- Transfer the tarballs to the dependent machine
- Extract all the tarballs to temp folder
- install using 'python setup.py install --user'
- Run the program :)
Details:
- Generate a requirements.txt using
pip freeze > requirements.txt
Getting tarballs from your python environment
- cd to your download folder
Run
pip download -r ../requirements.txt --no-binary :all:
. This downloads all requirements as tar.gz archive into current directoryRemember to download all the inner dependencies that are missing from target machine. I needed to also download setuptools-0.6c9 for Python 2.6.6
Transfer the download folder to the production machine(without internet and pip)
cd to download folder and run following command to install the dependency to the currently active 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
- Run your python script.
来源:https://stackoverflow.com/questions/56021133/offline-installation-of-dependant-python-modules-without-pip