Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hadisfr/3ecc1dd056e5d3463814bb52599fc8c4 to your computer and use it in GitHub Desktop.
Save hadisfr/3ecc1dd056e5d3463814bb52599fc8c4 to your computer and use it in GitHub Desktop.
Python2.7, Pip, Virtualenv Installation on Mac or Linux machines for the current user without sudo access

Installing Python2.7

If you download a different version it should work similarly.

cd ~
wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
tar -xzvf Python-2.7.13.tgz
cd Python-2.7.13
./configure 
make altinstall prefix=~/.local/

The configure and make step takes few minutes. Now python 2.7 would be present in ~/.local/bin. Add this to PATH. This is very important as the following steps depend on it.

export PATH=~/.local/bin:$PATH
python2.7  # should work fine

It is a good idea to add the export statement to ~/.bashrc file to load at login. You can also create a soft-link to python2.7 so that python command gives you v2.7

cd ~/.local/bin; ln -s python2.7 python

Lets talk about installing pip

Download the get-pip.py file and install it for the current user. It will leave pip and pip2.7 executables in ~/.local/bin.

cd ~
wget https://bootstrap.pypa.io/get-pip.py
python2.7 get-pip.py --user

Setting up Virtualenv and Shipping to another machine

pip install virtualenv --user
cd ~
mkdir venv
cd venv
virtualenv -p ~/.local/bin/python2.7  e1
virtualenv --relocatable e1
## To use e1
source ~/venv/e1/bin/activate
## pip install some libraries inside the env e1
## To exit
deactivate

For shipping it to a different machine Copy ~/.local and ~/venv/e1. You will get your python and installed packages on a different machine inside env e1. It is a good idea to make a tarball and scp to save some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment