Thursday, June 30, 2011

The proper way to install pip, virtualenv, and distribute for Python

The key bit to realize is that "virtualenv" installs "pip" and "distribute", which are the latest and bestest packaging tools for Python.

(optional) add these to ~/.bashrc:
PIP_REQUIRE_VIRTUALENV=true
PIP_RESPECT_VIRTUALENV=true

1. install system-level virtualenv
sudo aptitude install virtualenv

2. use it to create a clean "distribution" centered around a private Python executable and your own packaged scripts

virtualenv --no-site-packages --distribute ENV

3. activate it for this shell

. ENV/bin/activate

This modifies the local PATH, so now "python" is your private one. Add/remove packages to your heart's content without messing with the system-global one.

which pip
 #  /home/johnm/work/ex-package/ENV/bin/pip

4. verify by installing a package from the internet

pip install coverage
python -c 'import coverage'

5. verify by installing a local package

pip -v install Mypackage-0.1dev.tar.gz
python -c 'import mypackage'

Wednesday, May 18, 2011

I salute Fabrice Bellard

Recently the amazing hack of "boot Linux in a web page" has been circulating around. Bellard wrote a x86 emulator in JavaScript, then took the straight Linux binaries and was able to boot it. In a web page. At reasonable speeds. His distribution even includes a C compiler. This is amazing, but that's not all.

Bellard wrote the emulator QEMU, which lets you run one set of software "inside" another. It's mostly used for virtual machines, so you can run multiple operating systems inside a "host" OS. The guests can run Linux or Windows or whatever. The guest virtual machines can even be of different CPU types: ARM on a x86! This can be incredibly useful. But that's not all.

A large majority of video software uses the "ffmpeg" library. It's quite low level, but lets you do conversion of different screen sizes, bit rates, and codecs. Also written by Bellard, and now extended by a team for the last few years.

Among his other hacks are TCC, a tiny C compiler, which lets you use C as a scripting language. It's fast and complete enough to be used as a boot loader. That is, you can "boot" TCC, which then compiles and runs the Linux kernel. The entire thing. It recompiles on the fly.

Lastly he has some software to turn your computer into a TV transmitter. This is impossible, but he's found a way to do it by tweaking VGA video registers and timings and so forth.

I salute you, Fabrice Bellard.

Fabrice Bellard's Home Page