How to Manually Install a Pypi Module Without Pip/Easy_Install

How to manually install a pypi module without pip/easy_install?

  1. Download the package
  2. unzip it if it is zipped
  3. cd into the directory containing setup.py
  4. If there are any installation instructions contained in documentation, read and follow the instructions
    OTHERWISE
  5. type in python setup.py install

You may need administrator privileges for step 5. What you do here depends on your operating system. For example in Ubuntu you would say sudo python setup.py install


EDIT- thanks to kwatford (see first comment)

To bypass the need for administrator privileges during step 5 above you may be able to make use of the --user flag. This way you can install the package only for the current user.

The docs say:

Files will be installed into subdirectories of site.USER_BASE (written as userbase hereafter). This scheme installs pure Python modules and extension modules in the same location (also known as site.USER_SITE).

More details can be found here: http://docs.python.org/2.7/install/index.html

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.

Install python wheel file without using pip

It is. Actually .whl files are just zip archives, so you can just extract their content and play with libraries path variable to make it work.
Yet it is really bad practice.

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

Installing matplotlib and numpy without pip

If you have ability to download and install on your computer, I would recommend just installing/using the Anaconda distribution of Python, which has almost everything you need rolled in (including matplotlib and numpy) with the basics.

https://www.anaconda.com

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

How to install python packages in a private network

You can manually install Python packages if you have read access to the package repositories. Every Python package has a setup.py file in the root directory and you can do something like

python setup.py sdist

This creates a subdirectory called dist which contains a compressed archived file, tar.gz or .zip depending in your OS. You can pass this archived file to pip and install the package

pip3 install some-python-package.tar.gz


Related Topics



Leave a reply



Submit