下载ubuntu依赖包python脚本

HOWTO: Download package dependencies for offline installation
Have you ever been into trying to install a package in a computer that is not connected to the network? Keep reading to find solutions to this problem.

Follow these Steps:
Find out what packages have to be downloaded

Case 1: You have a recent synaptic version.

The first step would be to open Synaptic and select the package(s) you want to install. Then go to File -> Generate package download script and save it naming it as you want (herein referred as download_script_file).

Case 2: You don't have a recent synaptic version or you are not using any window manager.

Use grabpackages.py (attached). Type python grabpackages.py -h to see the help. This is the command you would use to download Inkscape and its dependencies:
Code:
python grabpackages.py -o download_script_file inkscape
Now take download_script_file to the computer with internet access.
Download the packages

Case 1: The computer with internet access has a linux OS with wget installed.

Open a terminal and cd to a suitable directory (e.g. cd /tmp).

Create a directory to download the packages and cd into it:
Code:
mkdir packages_dir
cd packages_dir
Copy download_script_file into this directory and execute it:
Code:
sh download_script_file
The script begins to download the files using wget.

Case 2: You have a Windows/Linux box but wget is not installed.

You could try one of these:
Install wget

In Debian/Ubuntu:
Code:
sudo apt-get install wget
In Redhat/Fedora:
Code:
yum install wget
In Windows: see here.
Generate an html page and download the packages from your browser

If you already have the download script file generated by synaptic, the easiest way is to use downloadscript2html.py (attached):
Code:
python downloadscript2html.py download_script_file download_page.html
If not, grabpackages.py (attached) will work too (using the --html option). Revisiting the Inkscape example:
Code:
python grabpackages.py --html -o download_page.html inkscape
Now open download_page.html in your browser and download the linked files in your download directory (here a download accelerator like DownThemAll is very useful, specially with large files).
Copy the packages to your PC

Copy the .deb files you downloaded to /var/cache/apt/archives:

From the directory where the .deb files are stored type:
Code:
sudo cp *.deb /var/cache/apt/archives
or start Nautilus as root and copy the files in the usual way.
Install the packages

Just open a terminal and type
Code:
sudo apt-get install <package_name(s)>
replacing <package_name(s)> with the name(s) of the program(s) you wanted to install (E.g. inkscape).


This should be pretty much everything.

Note:

The attached scripts are written in Python. In some systems Python is not installed by default. See http://www.python.org/download/ to solve this.

 

你可能感兴趣的:(linux,python,Debian,脚本,ubuntu)