如何离线安装软件包? [英] How to install packages offline?

查看:201
本文介绍了如何离线安装软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下载python软件包的最佳方法是什么,它是从pypi进行依赖以在另一台计算机上脱机安装的方法?有什么简单的方法可以通过pip或easy_install来做到这一点?我正在尝试在未连接到Internet的FreeBSD盒上安装请求库.

What's the best way to download a python package and it's dependencies from pypi for offline installation on another machine? Is there any easy way to do this with pip or easy_install? I'm trying to install the requests library on a FreeBSD box that is not connected to the internet.

推荐答案

如果该软件包位于PYPI上,则将其及其依赖项下载到某些本地目录中. 例如

If the package is on PYPI, download it and its dependencies to some local directory. E.g.


$ mkdir /pypi && cd /pypi
$ ls -la
  -rw-r--r--   1 pavel  staff   237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
  -rw-r--r--   1 pavel  staff   389741 Feb 22 17:10 Jinja2-2.6.tar.gz
  -rw-r--r--   1 pavel  staff    70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
  -rw-r--r--   1 pavel  staff  2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
  -rw-r--r--   1 pavel  staff  1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz
  -rw-r--r--   1 pavel  staff   488207 Apr 10 18:26 boto-2.3.0.tar.gz
  -rw-r--r--   1 pavel  staff   490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz

某些软件包可能必须手工归档到外观相似的tarball中.当我想要更新(不稳定)版本的东西时,我会做很多事情.某些软件包不在PYPI上,因此对它们也是如此.

Some packages may have to be archived into similar looking tarballs by hand. I do it a lot when I want a more recent (less stable) version of something. Some packages aren't on PYPI, so same applies to them.

假设您在~/src/myapp中有一个格式正确的Python应用程序. ~/src/myapp/setup.py将具有install_requires列表,该列表提及您在/pypi目录中拥有的一项或多项内容.像这样:

Suppose you have a properly formed Python application in ~/src/myapp. ~/src/myapp/setup.py will have install_requires list that mentions one or more things that you have in your /pypi directory. Like so:

  install_requires=[
    'boto',
    'Flask',
    'Werkzeug',
    # and so on

如果您希望能够在拥有所有必要依赖项的情况下运行您的应用程序,同时仍然对其进行黑客攻击,则可以执行以下操作:

If you want to be able to run your app with all the necessary dependencies while still hacking on it, you'll do something like this:


$ cd ~/src/myapp
$ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi

这样,您的应用将直接从您的源目录执行.您可以破解某些东西,然后重新运行该应用程序而无需重建任何内容.

This way your app will be executed straight from your source directory. You can hack on things, and then rerun the app without rebuilding anything.

如果要将应用程序及其依赖项安装到当前的python环境中,则将执行以下操作:

If you want to install your app and its dependencies into the current python environment, you'll do something like this:


$ cd ~/src/myapp
$ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .

在两种情况下,如果/pypi目录中不存在一个或多个依赖项,则构建将失败.它不会尝试从Internet滥发地安装丢失的东西.

In both cases, the build will fail if one or more dependencies aren't present in /pypi directory. It won't attempt to promiscuously install missing things from Internet.

我强烈建议在活动的虚拟环境中调用setup.py develop ...easy_install ...污染您的全球Python环境. (virtualenv是)几乎可以走的路.切勿在全局Python环境中安装任何东西.

I highly recommend to invoke setup.py develop ... and easy_install ... within an active virtual environment to avoid contaminating your global Python environment. It is (virtualenv that is) pretty much the way to go. Never install anything into global Python environment.

如果您构建了应用程序的计算机与要在其上部署应用程序的计算机具有相同的体系结构,则可以简单地将整个虚拟环境目录压缩到其中,然后将所有内容都打包到其中.不过,在压缩之前,您必须使虚拟环境目录可重定位(请参见-可重定位选项). 注意::目标计算机需要安装相同版本的Python,并且您的应用可能还必须预安装任何基于C的依赖项(例如,说您是否依赖PIL ,然后必须预安装libpng,libjpeg等).

If the machine that you've built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see --relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).

这篇关于如何离线安装软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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