skip to content
Notes && Anecdotes
A decorative, semi-related stock photo that adds less value than this comment.

Get python, pip, virtualenv without sudo



I don’t have sudo and life is awful on a cheap server / VPS. There is no python, or the wrong python version. How do I run my project?

Step 1: Get your desired python version

Python 2.7

mkdir python
cd python
mkdir src
cd src
tar xvfz Python-2.7.3.tgz
cd Python-2.7.3
mkdir ~/python/python27
./configure -prefix=/home/username/python/python27
make install
echo "export PATH=$HOME/python/python27/bin" >> .bashrc
source .bashrc

Bam, you got python without sudo!

Step 2: Get pip

cd ~/python
wget --no-check-certificate
tar xvfz setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python install
cd ..
wget --no-check-certificate
tar xvfz pip-1.1.tar.gz
cd pip-1.1
python install

Bam, you got python package manager without sudo!

Step 3: Get virtualenv

pip install virtualenv
pip install virtualenvwrapper

Done (sort of)

You should now have python2.7 with pip and virtualenvwrapper without having had sudo! Awesomesauce!

Now you might have to set up some path pointers to this python instance when you set up new projects on the serfver

Project Step 1: Get your project

git clone ...  # Whatever project you're doing
cd <projectname>
virtualenv --distribute env
source env/bin/activate
pip install -r requirements.txt

Project Step 2: Deploy

  • Go to your public-folder
  • make a fcgi-file with the following content:
import sys, os

# Add a custom Python path.
sys.path.insert(0, "/home/username/projectname/env")
sys.path.insert(13, "/home/username/project")
os.environ['DJANGO_SETTINGS_MODULE'] = 'mydjangoproject.settings'

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")
  • write the file and set permissions: chmod 755 projectname.fcgi
  • vim .htaccess with the following content:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST\_FILENAME} !-f
RewriteRule ^(.\*)$ projectname.fcgi/$1 \[QSA,L\]

Step 6: Settings

This you know best self. You probably want to edit the django setting file or something :)

PS: Don’t go hosting on Bluehost. Try Webfaction or Heroku: Then you’ll never have to run into this problem. EDIT PS: Don’t deal with servers. Deploy directly to a PAAS