Saturday, December 2, 2017

Install Python Packages without internet connection

Step 1: Install base packages from installation media (DVD)

[root@localhost pip-9.0.1]# yum install gcc python-devel python-setuptools

[root@localhost pip-9.0.1]# rpm -ql python-setuptools.noarch |grep easy_install.py
/usr/lib/python2.7/site-packages/easy_install.py
/usr/lib/python2.7/site-packages/easy_install.pyc
/usr/lib/python2.7/site-packages/easy_install.pyo
/usr/lib/python2.7/site-packages/setuptools/command/easy_install.py
/usr/lib/python2.7/site-packages/setuptools/command/easy_install.pyc
/usr/lib/python2.7/site-packages/setuptools/command/easy_install.pyo

Step 2: Install pip offline (Refer to step in appendix A to download pip-x.y.z.tar.gz)


[root@localhost pip-9.0.1]# python /usr/lib/python2.7/site-packages/easy_install.py ./pip-9.0.1.tar.gz
Processing pip-9.0.1.tar.gz
Writing /tmp/easy_install-LUeyTI/pip-9.0.1/setup.cfg
Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-LUeyTI/pip-9.0.1/egg-dist-tmp-8Ygk34
/usr/lib64/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
  warnings.warn(msg)
warning: no previously-included files found matching '.coveragerc'
warning: no previously-included files found matching '.mailmap'
warning: no previously-included files found matching '.travis.yml'
warning: no previously-included files found matching '.landscape.yml'
warning: no previously-included files found matching 'pip/_vendor/Makefile'
warning: no previously-included files found matching 'tox.ini'
warning: no previously-included files found matching 'dev-requirements.txt'
warning: no previously-included files found matching 'appveyor.yml'
no previously-included directories found matching '.github'
no previously-included directories found matching '.travis'
no previously-included directories found matching 'docs/_build'
no previously-included directories found matching 'contrib'
no previously-included directories found matching 'tasks'
no previously-included directories found matching 'tests'
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/bin
Installing pip2.7 script to /usr/bin
Installing pip2 script to /usr/bin

Installed /usr/lib/python2.7/site-packages/pip-9.0.1-py2.7.egg
Processing dependencies for pip==9.0.1
Finished processing dependencies for pip==9.0.1

Step 3: Install python packages (use ipython as example) (Refer to step in appendix B to download these package)


[root@localhost python]# ls -l ipython-deps/
total 2640
-rw-r--r--. 1 root root   6497 Dec  2 09:10 backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   9052 Dec  2 09:10 decorator-4.1.2-py2.py3-none-any.whl
-rw-r--r--. 1 root root  12427 Dec  2 09:10 enum34-1.1.6-py2-none-any.whl
-rw-r--r--. 1 root root 758874 Dec  2 09:10 ipython-5.5.0-py2-none-any.whl
-rw-r--r--. 1 root root  26343 Dec  2 09:10 ipython_genutils-0.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  16631 Dec  2 09:10 pathlib2-2.3.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  55699 Dec  2 09:10 pexpect-4.3.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   6864 Dec  2 09:10 pickleshare-0.7.4-py2.py3-none-any.whl
-rw-r--r--. 1 root root 247937 Dec  2 09:10 prompt_toolkit-1.0.15-py2-none-any.whl
-rw-r--r--. 1 root root  39072 Dec  2 09:10 ptyprocess-0.5.2-py2.py3-none-any.whl
-rw-r--r--. 1 root root 841734 Dec  2 09:10 Pygments-2.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  29670 Dec  2 09:10 scandir-1.6.tar.gz
-rw-r--r--. 1 root root 489406 Dec  2 09:10 setuptools-38.2.3-py2.py3-none-any.whl
-rw-r--r--. 1 root root  12663 Dec  2 09:10 simplegeneric-0.8.1.zip
-rw-r--r--. 1 root root  10702 Dec  2 09:10 six-1.11.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  74730 Dec  2 09:10 traitlets-4.3.2-py2.py3-none-any.whl
-rw-r--r--. 1 root root  21014 Dec  2 09:10 wcwidth-0.1.7-py2.py3-none-any.whl


# --no-index: Ignore package index (Base URL of Python Package Index), only looking at --find-links URLs instead

[root@localhost python]# pip install --no-index --find-links=ipython-deps/ ipython
Collecting ipython
Collecting prompt-toolkit<2.0.0,>=1.0.4 (from ipython)
Requirement already satisfied: decorator in /usr/lib/python2.7/site-packages (from ipython)
Collecting pexpect; sys_platform != "win32" (from ipython)
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython)
Collecting setuptools>=18.5 (from ipython)
Collecting pygments (from ipython)
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython)
Collecting traitlets>=4.2 (from ipython)
Collecting simplegeneric>0.8 (from ipython)
Collecting pickleshare (from ipython)
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
Collecting six>=1.9.0 (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython)
Collecting ipython-genutils (from traitlets>=4.2->ipython)
Collecting enum34; python_version == "2.7" (from traitlets>=4.2->ipython)
Installing collected packages: wcwidth, six, prompt-toolkit, ptyprocess, pexpect, backports.shutil-get-terminal-size, setuptools, pygments, scandir, pathlib2, ipython-genutils, enum34, traitlets, simplegeneric, pickleshare, ipython
  Found existing installation: setuptools 0.9.8
    Uninstalling setuptools-0.9.8:
       Successfully uninstalled setuptools-0.9.8
  Running setup.py install for scandir ... done
  Running setup.py install for simplegeneric ... done
Successfully installed backports.shutil-get-terminal-size-1.0.0 enum34-1.1.6 ipython-5.5.0 ipython-genutils-0.2.0 pathlib2-2.3.0 pexpect-4.3.0 pickleshare-0.7.4 prompt-toolkit-1.0.15 ptyprocess-0.5.2 pygments-2.2.0 scandir-1.6 setuptools-38.2.3 simplegeneric-0.8.1 six-1.11.0 traitlets-4.3.2 wcwidth-0.1.7
[root@localhost python]#

Step 4: Post Verification


[root@localhost python]# ipython
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: quit

Appendix A: Download PIP (https://pypi.python.org/simple/pip/)

[root@localhost python]# curl -o pip-9.0.1.tar.gz https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1169k  100 1169k    0     0   460k      0  0:00:02  0:00:02 –:--:--  460k


Appendix B: Download Packages and their dependencies

[root@localhost python]# pip download ipython -d ipython-deps
Collecting ipython
  Downloading ipython-5.5.0-py2-none-any.whl (758kB)
    100% |████████████████████████████████| 768kB 373kB/s
  Saved ./ipython-deps/ipython-5.5.0-py2-none-any.whl
Collecting prompt-toolkit<2.0.0,>=1.0.4 (from ipython)
  Downloading prompt_toolkit-1.0.15-py2-none-any.whl (247kB)
    100% |████████████████████████████████| 256kB 583kB/s
  Saved ./ipython-deps/prompt_toolkit-1.0.15-py2-none-any.whl
Collecting decorator (from ipython)
  Downloading decorator-4.1.2-py2.py3-none-any.whl
  Saved ./ipython-deps/decorator-4.1.2-py2.py3-none-any.whl
Collecting pexpect; sys_platform != "win32" (from ipython)
  Downloading pexpect-4.3.0-py2.py3-none-any.whl (55kB)
    100% |████████████████████████████████| 61kB 872kB/s
  Saved ./ipython-deps/pexpect-4.3.0-py2.py3-none-any.whl
Collecting backports.shutil-get-terminal-size; python_version == "2.7" (from ipython)
  Downloading backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
  Saved ./ipython-deps/backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Collecting setuptools>=18.5 (from ipython)
  Downloading setuptools-38.2.3-py2.py3-none-any.whl (489kB)
    100% |████████████████████████████████| 491kB 658kB/s
  Saved ./ipython-deps/setuptools-38.2.3-py2.py3-none-any.whl
Collecting pygments (from ipython)
  Downloading Pygments-2.2.0-py2.py3-none-any.whl (841kB)
    100% |████████████████████████████████| 849kB 830kB/s
  Saved ./ipython-deps/Pygments-2.2.0-py2.py3-none-any.whl
Collecting pathlib2; python_version == "2.7" or python_version == "3.3" (from ipython)
  Downloading pathlib2-2.3.0-py2.py3-none-any.whl
  Saved ./ipython-deps/pathlib2-2.3.0-py2.py3-none-any.whl
Collecting traitlets>=4.2 (from ipython)
  Downloading traitlets-4.3.2-py2.py3-none-any.whl (74kB)
    100% |████████████████████████████████| 81kB 2.0MB/s
  Saved ./ipython-deps/traitlets-4.3.2-py2.py3-none-any.whl
Collecting simplegeneric>0.8 (from ipython)
  Downloading simplegeneric-0.8.1.zip
  Saved ./ipython-deps/simplegeneric-0.8.1.zip
Collecting pickleshare (from ipython)
  Downloading pickleshare-0.7.4-py2.py3-none-any.whl
  Saved ./ipython-deps/pickleshare-0.7.4-py2.py3-none-any.whl
Collecting wcwidth (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
  Downloading wcwidth-0.1.7-py2.py3-none-any.whl
  Saved ./ipython-deps/wcwidth-0.1.7-py2.py3-none-any.whl
Collecting six>=1.9.0 (from prompt-toolkit<2.0.0,>=1.0.4->ipython)
  Downloading six-1.11.0-py2.py3-none-any.whl
  Saved ./ipython-deps/six-1.11.0-py2.py3-none-any.whl
Collecting ptyprocess>=0.5 (from pexpect; sys_platform != "win32"->ipython)
  Downloading ptyprocess-0.5.2-py2.py3-none-any.whl
  Saved ./ipython-deps/ptyprocess-0.5.2-py2.py3-none-any.whl
Collecting scandir; python_version < "3.5" (from pathlib2; python_version == "2.7" or python_version == "3.3"->ipython)
  Downloading scandir-1.6.tar.gz
  Saved ./ipython-deps/scandir-1.6.tar.gz
Collecting ipython-genutils (from traitlets>=4.2->ipython)
  Downloading ipython_genutils-0.2.0-py2.py3-none-any.whl
  Saved ./ipython-deps/ipython_genutils-0.2.0-py2.py3-none-any.whl
Collecting enum34; python_version == "2.7" (from traitlets>=4.2->ipython)
  Downloading enum34-1.1.6-py2-none-any.whl
  Saved ./ipython-deps/enum34-1.1.6-py2-none-any.whl
Successfully downloaded ipython prompt-toolkit decorator pexpect backports.shutil-get-terminal-size setuptools pygments pathlib2 traitlets simplegeneric pickleshare wcwidth six ptyprocess scandir ipython-genutils enum34

No comments:

Post a Comment