Skip to content

Instantly share code, notes, and snippets.

@vinay-vissh
Last active June 10, 2021 14:24
Show Gist options
  • Save vinay-vissh/8e3fcf1b1125712e28f94e2fa47fa904 to your computer and use it in GitHub Desktop.
Save vinay-vissh/8e3fcf1b1125712e28f94e2fa47fa904 to your computer and use it in GitHub Desktop.
(Deprecated) Installing python v2.x on linux without internet and root-level access.

It is assumed that:

  • Any required file is being downloaded on some other computer and transferred to our target linux machine by some means.
  • Installing v2.7.15 of python - Downloaded as Gzipped source tarball from Python.org.

Installation:

  1. Create some directories - to keep it all organized:
    mkdir $HOME/packages && mkdir $HOME/packages/src && mkdir $HOME/packages/installed

  2. Move Python-2.7.15.tgz to $HOME/packages/src

  3. Extract: cd $HOME/packages/src && tar -xzf Python-2.7.15.tgz

  4. Build zlib.
    cd Python-2.7.15/Modules/zlib
    ./configure --prefix=$HOME/packages/installed
    make - Ignore No rule to make target... Stop.
    make install

  5. Return to the parent Python-2.7.15 folder: cd ../..

  6. Build python.

    1. Configure: ./configure --prefix=$HOME/packages/installed --exec-prefix=$HOME/packages/installed
    2. Manually add zlib option: echo 'zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz' >> Modules/Setup.local
    3. make
    4. make install
  7. Determine your user-level environment variable file - .profile or .bash_profile or something else.
    Say: pathFile=$HOME/.bash_profile

  8. Edit $pathFile:

    1. Update $PATH
      Add $HOME/packages/installed/bin before any other location so that it can override any system-wide installed python.

    2. Add $LD_LIBRARY_PATH - That is:
      LD_LIBRARY_PATH=$HOME/packages/installed/lib
      export $LD_LIBRARY_PATH

  9. Load new values of environment variables: source $pathFile
    You might need to rerun this step whenever you start a new terminal.

  10. Verify:

  • python: python --version
  • pip: pip --version
  1. Clean up: rm -r $HOME/packages/src/Python-2.7.15


Installing a python package:

  1. From source code with setup.py

    • python -m pip install .
    • python setup.py install
  2. From .whl file

    • python -m pip install fileName.whl
    • python -m wheel install fileName.whl

Installed packages:

  1. List: python -m pip list

  2. Specific package: python -m pip show packageName

    You will get something like:

    Name: setuptools
    Version: 39.0.1
    Summary: Easily download, build, install, upgrade, and uninstall Python packages
    


Uninstall:

  1. Remove $HOME/packages/installed/bin from $PATH in your $pathFile.
  2. Load the new $PATH: source $pathFile
  3. rm -r $HOME/packages/installed/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment