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:
-
Create some directories - to keep it all organized:
mkdir $HOME/packages && mkdir $HOME/packages/src && mkdir $HOME/packages/installed
-
Move Python-2.7.15.tgz to
$HOME/packages/src
-
Extract:
cd $HOME/packages/src && tar -xzf Python-2.7.15.tgz
-
Build zlib.
cd Python-2.7.15/Modules/zlib
./configure --prefix=$HOME/packages/installed
make
- Ignore No rule to make target... Stop.make install
-
Return to the parent Python-2.7.15 folder:
cd ../..
-
Build python.
- Configure:
./configure --prefix=$HOME/packages/installed --exec-prefix=$HOME/packages/installed
- Manually add zlib option:
echo 'zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz' >> Modules/Setup.local
make
make install
- Configure:
-
Determine your user-level environment variable file - .profile or .bash_profile or something else.
Say:pathFile=$HOME/.bash_profile
-
Edit $pathFile:
-
Update $PATH
Add$HOME/packages/installed/bin
before any other location so that it can override any system-wide installed python. -
Add $LD_LIBRARY_PATH - That is:
LD_LIBRARY_PATH=$HOME/packages/installed/lib
export $LD_LIBRARY_PATH
-
-
Load new values of environment variables:
source $pathFile
You might need to rerun this step whenever you start a new terminal. -
Verify:
- python:
python --version
- pip:
pip --version
- Clean up:
rm -r $HOME/packages/src/Python-2.7.15
Installing a python package:
-
From source code with
setup.py
python -m pip install .
python setup.py install
-
From
.whl
filepython -m pip install fileName.whl
python -m wheel install fileName.whl
Installed packages:
-
List:
python -m pip list
-
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:
- Remove
$HOME/packages/installed/bin
from $PATH in your $pathFile. - Load the new $PATH:
source $pathFile
rm -r $HOME/packages/installed/*