Harsh J

Memoirs of a QWERTY Keyboard

Archive for May, 2009

Install Python Packages locally

8 comments

There’s a great feature in Python versions 2.6 and up that I hardly see being used; it’s the ability to install modules and packages in a per-user local directory. I like this feature since it doesn’t have any super-user power requirements and lets me install packages, modules and even scripts in my own Home directory and use it just as normally as the other global files.

To do so, one must first create the local site-packages directory, and then place the required package or module file or folder under it. The following commands are all for UNIX. ~/ expands to the user’s $HOME automatically.

# To create the required directory
mkdir -p ~/.local/lib/python2.6/site-packages

Now place the module or package folder under this directory, or link to it for achieving the same installation effect as you would with a global site-packages directory. For example, for my django copy from svn I’d do:

ln -s ~/.django-svn/django-trunk/django ~/.local/lib/python2.6/site-packages/django

Running the Python interpreter (in the same user account) will show this working:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

So there you have it, when you want a package just for your user account while developing just put it under the local site-packages directory. Python automatically adds this to its path (PYTHONPATH).

References: PEP 370 (Has notes for OS X and Windows users)

Written by Harsh

May 21st, 2009 at 11:00 am

Posted in Linux,Software

Tagged with ,

Clearing all log files in /var/log

leave a comment

Stupid things you end up writing when you worry about filling disk spaces at 3 AM in the morning of the day right before your exams begin. The following will delete all your log files in a safe manner, by simply rewriting them to null.

cd /var/log
for file in `find .`
do
	if [ -f $file ];
	then
		cat /dev/null > $file
	fi
done

Suggest better methods if known, and thank you!

Optionally, get in there and delete those now-stagnant .gz files with the following:

find /var/log -name "*.gz" | xargs rm

P.s. So much for BS code highlight plugins printing angled brackets in HTML notations when asked to do bash.

Written by Harsh

May 19th, 2009 at 3:31 am

Posted in Blog,Linux,Personal

Tagged with , ,

Get rid of all PulseAudio problems – Use OSS

22 comments

You might think, like I did: Isn’t OSS dead? Didn’t ALSA replace it ages ago?

Open Sound System - Much better!

Open Sound System - Much better!

The answer, as I learnt, was both yes and no. It did die, only to be revived later by 4Front Technologies who developed it under a commercial license for quite sometime. It went GPL only recently, although with a paid premium-support and on certain platforms only. The improvements made in it are simply amazing. I’ll leave the rest of the mystery to be covered by 4Front’s own blog post. It’s a nice read :)

The following guide on how to shift to OSS from PulseAudio/ALSA is for Ubuntu (Jaunty Jackalope, 9.04*) users alone. A proper guide to ArchLinux’s solution might be found here.
Read the rest of this entry »

Written by Harsh

May 16th, 2009 at 9:10 pm

PyQt – Signals, Slots and Layouts Tutorial

18 comments

Note: If you’re new to using PyQt but are interested in great cross-platform GUI application development please read the PyQt Introduction article.

Having seen how a simple PyQt application code looks, let’s delve into user-interaction. We’ll learn about Qt’s signal-to-slot connection model for processing input and other events, and layouts for proper placement of widgets on a window.

The PyQt Class Hierarchy

PyQt is completely built upon the Object-Oriented concepts, so it is important to understand how all classes are related to each other in it.

Almost all GUI classes extend upon their Abstract class which defines common behaviour for similar widgets. These abstract classes, or any widget class, inherit QWidget, the base class of all drawable GUI components. QWidget inherits QObject, a class that has nothing to do with GUI but forms the base class of every PyQt class and helps provide the framework-related features.

The following hierarchy diagram depicts this clearly for the QPushButton class:

The QPushButton Class Hierarchy

The QPushButton Class Hierarchy

The QPaintDevice class helps draw (or paint) things on the screen, thus its also used with anything that’s drawable – We’ll learn more about Painting in a later article.

References: QWidget
Read the rest of this entry »

Written by Harsh

May 14th, 2009 at 11:37 am

Posted in Software

Tagged with , , , , ,

Ubuntu 9.04 Python 2.6 Site-Packages Directory

5 comments

Strangely the site-packages directory used by Python (2.6) to place/install modules and packages is nowhere to be found in Ubuntu’s Jaunty Jackalope. The newer directory is called dist-packages, no idea why (Only know that it sounds like its for distribution-installed modules).

So to place a package or a link to one, simply do so in the /usr/local/lib/python2.6/dist-packages/ directory.

Written by Harsh

May 13th, 2009 at 1:09 am

Posted in Linux,Software

Tagged with , ,