Monday, April 11, 2011

How to satisfy dependencies for your python projects

You need a text file in your project with your dependencies, i.e. REQUIREMENTS, with a list of packages your project depends on.

PIP's requirement file format (detailed):
<package-name>[==<version>]
-e <repository address>#egg=<desirable-package-name>

And when you need to init the project in a new place you'd like to run:
# init or activate a virtual environment
(virtual-env)$ pip install -r REQUIREMENTS

That's all. You packages will be automatically installed. And you can run that command whenever you want (i.e. a new dependency has been added) - it just recheck all mentioned packages and install new ones.

Thursday, April 7, 2011

Python's virtual environment

You probably would like to use separate sets of packages for your projects and whilst not to spoil your system's environment. This problem can be solved by using virtual environments.

Make initial setup:


To configure virtualenvwrapper:

  1. Create a directory for the virtual environments:
    mkdir ~/projects/.envs
  2. Add to ~/.bashrc:
    export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
    export WORKON_HOME=~/projects/.envs
    export PROJECT_HOME=~/projects
    
    source /usr/local/bin/virtualenvwrapper.sh
  3. Run:
    source ~/.bashrc

Initial setup has been done. Now let's create a new virtual enviroment for Test project in ~/projects/test
mkvirtualenv test
workon test
Now you're in the 'test' environment. To install new packages you can use, for instance, pip.

Friday, April 1, 2011

Big brother is watching you

Do you doubt whether Google knows about your Wi-Fi router location? Try this on your *nix-machine:

iwlist wlan0 scan | sed -n 's/.* Address: //p;T;s/ //g;q' | sed 's/.*/{version:1.1.0,host:maps.google.com,request_address:true,address_language:'${LANG/.*/}',wifi_towers:[{mac_address:"&",signal_strength:8,age:0}]}/' | curl -sX POST -d @- www.google.com/loc/json | sed -e 'h;s/.*latitude":\([^,]*\).*/\1/;G;s/\n[^\n]*longitude":\([^,]*\).*/,\1\n/;s|^|http://maps.google.com/maps?q=|;x;s/[,{]/\n/g;s/["}]//g;s/:/\t/g;s/\n//;G'

Nice, isn't it?