Notes and anecdotes

Techstuff rambling

Get python, pip, virtualenv without sudo

Case: You don’t have sudo and life is awful on a cheap VPS or similar.

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

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

Step 3: Get virtualenv

pip install virtualenv
pip install virtualenvwrapper

Done (sort of)

You should now have python2.7 with pip and virtualenvwrapper.

Step 4: Get down your project

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

Step 5: Deploy

  • Go to your public-folder
  • make a fcgi-file (vim projectname.fcgi 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 (in the same folder 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 :)

Thanks to

PS: Don’t go hosting on Bluehost. Try Webfaction or Heroku: Then you’ll never have to run into this problem.


tomfa • 2014-12-28

Previous Post

Next Post