无需PIP即可离线安装相关的python模块 [英] Offline installation of dependant python modules without PIP

查看:1213
本文介绍了无需PIP即可离线安装相关的python模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是 Python脱机软件包安装的重复版本,因为答案要求点子出现.我的前提是点子"不可用.

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.

我的python脚本依赖于 Github库.我需要创建一个包含此依赖关系的自给自足的tarball,并且可以提取并在我的生产服务器上运行,该服务器无法访问Internet或pip .但是我有Python 2.6.6/Python 2.7

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

我已经在本地计算机(具有Internet)上创建了virtualenv,并使用pip安装了依赖项. pip下载了从属库.我通过

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

下载的内容是

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

我还使用install_requires创建了setup.py,其中包含所有requirements.txt的内容(此

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",
    ],
)

我尝试运行以下命令来安装这些脚本(pip不可用)

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

注意:上面的命令在本地新创建的virtualenv上有效.

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

推荐答案

不使用pip进行安装需要您直接从tarball归档文件进行安装.所以,

Installing without pip requires you to install from the tarball archive directly. So,

  1. 首先,获取所有tarball归档文件的依赖项
  2. 将压缩包传输到从属计算机
  3. 将所有压缩包提取到临时文件夹
  4. 使用"python setup.py install --user"安装
  5. 运行程序:)


详细信息:


Details:

  1. 使用pip freeze > requirements.txt
  2. 生成requirements.txt
  3. 从python环境中获取压缩包

  1. Generate a requirements.txt using pip freeze > requirements.txt
  2. Getting tarballs from your python environment

  • cd到您的下载文件夹
  • 运行pip download -r ../requirements.txt --no-binary :all:.这会将所有要求作为tar.gz存档下载到当前目录中

  • cd to your download folder
  • Run pip download -r ../requirements.txt --no-binary :all:. This downloads all requirements as tar.gz archive into current directory

记住要下载目标计算机上缺少的所有内部依赖项.我还需要下载 setuptools-9 a>适用于Python 2.6.6

Remember 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

将下载文件夹传输到生产机器(没有Internet和pip)

Transfer the download folder to the production machine(without internet and pip)

cd下载文件夹并运行以下命令以将依赖项安装到当前活动的python.

cd to download folder and run following command to install the dependency to the currently active python.

install_tarball_python.sh [tar.gz文件]

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

  1. 运行您的python脚本.

这篇关于无需PIP即可离线安装相关的python模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆