How to Install Packages Offline

How to install packages offline?

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

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.

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.

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 .

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.

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.

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).

Install python packages offline on server

Download all the packages you need and send them to the server where you need to install them. It doesn't matter if they have *whl or *tar.gz extension. Then install them one by one using pip:

pip install path/to/package

or:

python -m pip install path/to/package

The second option is useful if you have multiple interpreters on the server (e.g. python2 and python3 or multiple versions of either of them). In such case replace python with the one you want to use, e.g:

python3 -m pip install path/to/package

If you have a lot of packages, you can list them in a requirement file as you would normally do when you have access to the internet. Then instead of putting the names of the packages into the file, put the paths to the packages (one path per line). When you have the file, install all packages by typing:

python -m pip install -r requirements.txt

In the requirements file you can also mix between different types of the packages (*whl and *tar.gz). The only thing to take care about is to download the correct versions of the packages you need for the platform you have (64bit packages for 64bit platform etc.).

You can find more information regarding pip install in its documentation.

Python: install package offline with dependencies with Pip?

This question seems to have already been answered here

However, here is a quick summary:

  1. Upload your package to the Python Package Index (PyPI)
  2. Download the package using pip on a machine with internet connection, then turn the package into a .tar file

    mkdir ~/some_directory
    pip download some_package -d "~/some_directory"
    tar -cvfz some_package.tar some_directory
  3. Once in .tar format, you can install the package without internet connection on a machine with Python.

    tar -xzvf some_package.tar
    cd some_directory
    pip install some_package-x.x.x-py2.py3-x-x.whl -f ./ --no-index

installing python packages without internet and using source code as .tar.gz and .whl

This is how I handle this case:

On the machine where I have access to Internet:

mkdir keystone-deps
pip download python-keystoneclient -d "/home/aviuser/keystone-deps"
tar cvfz keystone-deps.tgz keystone-deps

Then move the tar file to the destination machine that does not have Internet access and perform the following:

tar xvfz keystone-deps.tgz
cd keystone-deps
pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index

You may need to add --no-deps to the command as follows:

pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index --no-deps

Offline installation of dependent python modules without PIP

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

  1. First, get all the tarball archives for the dependencies
  2. Transfer the tarballs to the dependent machine
  3. Extract all the tarballs to temp folder
  4. install using 'python setup.py install --user'
  5. Run the program :)

Details:

  1. Generate a requirements.txt using pip freeze > requirements.txt
  2. 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 directory

      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

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

  4. 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

  1. Run your python script.

How can I install software or packages without Internet (offline)?

Check out Keryx; it's an offline repository manager.

How does it work? It lets you download updates and new programs (with dependencies) to your flash drive.

Its interface is similar to synaptic, but it works from a pendrive (it doesn't need installation). Unfortunately, the GUI needs wxwidgets, which don't come preinstalled on Ubuntu (they're cross-platform and installable from here and Ubuntu repository here). It can only install software in a Ubuntu system, but you can download the updates or new packages in any Linux, Windows or OS X.

Here you can find a tutorial.

Another detailed step-by-step tutorial is in this answer.

Launchpad also hosts downloadable files.

A screenshot:

Screenshoot

Anaconda install packages without connection

Solved! This is working behind a company proxy. Here with plotly as example

  1. download package from https://repo.continuum.io/pkgs/main/noarch/

example: plotly-4.4.1-py_0.tar.bz2


  1. safe package to C:/Temp/noarch/ folder (if it doesn't exist, create it)

  2. in C:/Temp/noarch/ folder press shift + rightclick (open console) or use anaconda prompt and go to folder

  3. type in

conda install plotly-4.4.1-py_0.tar.bz2 (other: conda install “package”)
example: C:\Temp\noarch>conda install plotly-4.4.1-py_0.tar.bz2



Related Topics



Leave a reply



Submit