Tag Archives: python

[HOWTO] Install easy_install and pip in Python 3 (Windows)

I am just starting with Python 3 on Windows and I wanted to install easy_install and/or pip for installing other available packages easily. However, I found that setuptools setup for Python 3.3.2 (the version I am using) is not available.

I discovered distribute, a fork of setuptools, which provides easy_install. I downloaded source from Python Package page for distribute and extracted it. In the elevated command prompt (cmd->Run as Administrator), I changed to extracted directory and then ran distribute_setup.py. Then, easy_install was successfully installed in Python_Directory\Scripts. Then, I could install pip by changing directory to Scripts and running the following:

easy_install pip

Hope this helps.

[HOWTO] (Python Plasmoids – Part 1) Write Hello World Plasma Applet in Python

I am new to KDE and I have come to like the plasmoids on the Desktop. They can be used to display information (eg. Weather, Time, News) or can be used to carry out some tasks (upload images/text to web, check mail etc) easily.

I don’t have any experience of Plasmoid development. I have decided to learn to write Plasmoids. I have moderate knowledge of Python.. I am learning Plasmoid development in Python and will be posting my experience. Feel free to learn with me or correct me if I am wrong.

I will be using Fedora 14 with KDE 4.5 for all my development and testing. However, other distros with any sub-version of KDE 4 should work fine. I will be citing all the references and where you can learn more.

I will be using Kwrite and KDevelop to develop plasmoids. However, you can pick any editor of choice.

For Hello World plasmoid, create a directory called hello anywhere you want. Also, create the following directory structure inside hello:

├── contents
│   └── code

The directory structure must be as shown above. or the plasmoid will not work.

Now, we will need a metadata for the plasmoid. This metadata file will contain the name, version, author-name, type of plasmoids and other information about the plasmoid. It should be inside the plasmoid directory (i.e. inside hello in this case). Here is my sample of metadata.desktop.

[Desktop Entry]
Name=Hello World
Comment=A Basic Hello World Example


Most of the fields are self-explanatory and to learn about the fields and other choices, see here.

As we have specified in X-Plasma-MainScript field in metadata.desktop, we will now create the file hello/contents/code/main.py. Note that you can use any filename for main.py but you will have to change in metadata.desktop accordingly.

The following is the very basic main.py which does absolutely nothing:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript
class MainApplet(plasmascript.Applet):
    def __init__(self,parent,args=None):
def CreateApplet(parent):
    return MainApplet(parent)

If the above plasmoid is run, you will see no output at all, just an empty plasmoid.
To run it, cd to the directory where you created the hello directory and run the following:

plasmoidviewer hello

If everything goes right, you will be able to see something like the following:

If any error occurs, you can see the output in the terminal to see whats wrong and hopefully fix it.

After running the application, lets analyse what we have done here.

Line 1-4 are import statements. If you are familiar with Python, you must be familiar with them. They are basically statements which tells the interpretor where to look for the functions and classes used in the program. Those are the minimum ones you will need for your Python plasmoids to work.

Lines 6-8 define a class derived from plasmascript.Applet. There must be at least one such class for your plasmoid to work. The name of the class may be anything you like. The class’ __init__ function initializes just the same function of base class which is to say it does nothing at all. While developing plasmoids later, you may want to do some stuff even prior to initialization of plasmoid. That stuff goes in this function.

There must be yet another function Createapplet() which must take 1 argument “parent” and pass it as initializer for the object of class derived from plasmascript.Applet and return the object. This function is in lines 10-11.

We have returned the Applet object as it is without modifications. We will now add some stuff to the Applet object before returning. In this tutorial, we will just add a label saying “Hello World”. To add a label however, we need to have a layout. So,we set a layout and then add a label on top of it.
To do that, we will be using init() method which is called after the applet is initialized and added. Here is the new code for main.py:

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript

class MainApplet(plasmascript.Applet):
    def __init__(self,parent,args=None):
    def init(self):
        layout=QGraphicsLinearLayout(Qt.Vertical, self.applet)
        label = Plasma.Label(self.applet)
        label.setText("Hello World")
def CreateApplet(parent):
    return MainApplet(parent)

The added code is the init() from line 10-15. First, a variable layout is set as QGraphicsLinearLayout(). This takes two arguments, one is the parent and the other is either Qt.Vertical or Qt.Horizontal. This layout orientation parameter decides whether the added items (if there are more than one) are arranged vertically or horizontally.

In line 12, a new Plasma.Label object is created. It takes in parent as the constructor argument. Other plasma widgets are available here. There is no Python specific documents as of now but the C++ documents work fine and it is easy to figure out how to use it in Python.

In line 13, we use a method setText() of Plasma.Label to set the text of the label and in the next line, we add the item to the layout we created earlier. Finally, in line 15 we set the layout we created as the label for the current applet.

When done testing, you may want to install the plasmoid to see how it looks on the desktop. To do that, you must zip it install it using plasmapkg. Change to hello/ directory and run the following to zip it to hello.zip:

zip -r ../hello.zip ./

Now, run the following to install it:

plasmapkg -i hello.zip

Now, you can add the plasmoid to your desktop. To remove it, just run:

plasmapkg -r hello

Here is what we have at the end:


This is a simple tutorial from a newbie to create Plasmoids in Python. However, we did not do any useful work with it. In the next tutorial, I will try to cover my experience creating something useful.



[SOLVED] Module DateTime.DateTime, line 1145, in toZone

I am using Ubuntu 10.10 Maverick Meerkat and live in Nepal, timezone Asia/Kathmandu. I have been trying to setup Plone CMS in my local computer for learning to build sites with Zope/Plone. However, I had been getting errors.

I installed Plone 3.3.5 on my Ubuntu 10.10 Maverick Meerkat 64bit Desktop with Plone Unified Installer – for Linux/BSD/OS X/UNIX/Solaris. The installation was successful.

Then I ran the instance of Zope by changing directory to where my Plone is installed and running the following in terminal:

cd /usr/local/Plone
sudo ./bin/instance fg

Then I could browse the url http://localhost:8080/manage (I had changed the port number to 8888 ).

However, when I tried to create a Plone Site using Zope interface, I got the following error:

Site Error

An error was encountered while publishing this resource.

Error Type: KeyError
Error Value: ”

I see the following error in the terminal:

Module DateTime.DateTime, line 1145, in toZone
KeyError: ”
Unhandled exception in thread started by
Traceback (most recent call last):
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/ZServer/PubCore/ZServerPublisher.py”, line 25, in __init__
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/ZPublisher/Publish.py”, line 401, in publish_module
environ, debug, request, response)
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/ZPublisher/Publish.py”, line 227, in publish_module_standard
if request is not None: request.close()
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/ZPublisher/BaseRequest.py”, line 211, in close
notify(EndRequestEvent(None, self))
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/zope/event/__init__.py”, line 23, in notify
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/zope/component/event.py”, line 26, in dispatch
for ignored in zope.component.subscribers(event, None):
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/zope/component/_api.py”, line 130, in subscribers
return sitemanager.subscribers(objects, interface)
File “/usr/local/Plone/Zope-2.10.11-final-py2.4/lib/python/zope/component/registry.py”, line 290, in subscribers
return self.adapters.subscribers(objects, provided)
AttributeError: adapters

I tried adding the following in buildout.cfg under instance section:

zope-conf-additional =
        TZ Asia/Katmandu

as instructed here and running buildout again but this did not work for me as I got the same error again.

I then installed Ubuntu 10.04 Lucid Lynx 32bit Server in Virtualbox and installed Plone again. This time I used Python 2.4 from Hardy repository rather than having it built by Plone installer. I used the tutorial here for rest of the stuff. But I got the same error again.

I then thought it was a Ubuntu specific issue and then installed CentOS 5.5 minimal in Virtualbox and installed Plone again. This did not work either. The same error appeared.

I then installed Plone 4 using Python 2.6 but the same error appears in instance.log.

In the Virtualbox installation of Ubuntu 10.04, I changed the timezone to Asia/Alaska and then the problem was gone. To do so, I did the following:

sudo dpkg-reconfigure tzdata

And then I selected US, Alaska. I then changed the buildout.c
I changed buildout.cfg to reflect the change in timezone:

zope-conf-additional =
        TZ US/Alaska

and ran buildout again.

sudo ./bin/buildout

Then the error no longer shows and I can create page.

I don’t know if it is a python issue, or Datetime bug. I will dig into it later. But for now, Plone works.

[HOWTO] Make Ubuntu 10.04 Lucid Lynx Mono Free

Ubuntu 10.04 comes with 3 default applications that depend on mono. They are
F-Spot, a photo manager
Tomboy, a note taking application
Gbrainy, brain teaser game and trainer
To get rid of mono and still keep the functionality, we need non-mono alternatives to these applications. Lets look at those. But first, let me write something about why someone may want to remove Mono.

Why remove Mono?
There are several reasons why someone may want to remove Mono from their Ubuntu installation. You may want to gain some free space. Mono takes up a lot of space for just a few applications. If you remove and replace them with others. This may not seem important if you want to run Ubuntu off normal harddisks these days, but it may be crucial if you want to remaster Ubuntu with few added applications and still want to distribute it on a CD or limited sized USB drive.
You may want to remove Mono for other reasons like it is an implementation of standard set by Microsoft or just because it is a short name for a contagious disease.

Why not remove Mono?
You may not want to remove Mono if you just want to free some space from your installation because it may not be the case when you start installing other applications based on Mono. You see, the alternatives also have dependencies and the different dependencies for all the alternatives may occupy more space than Mono.
Also, Mono seems to be a popular platform and there are many great applications like Docky, Banshee, Beagle etc. which need it. Moreover, many new applications may come up which need Mono and you may have to install it anyway.

Enough of that. Now, lets get to the applications.
F-Spot is to be removed from default install from Ubuntu 10.10 Maverick Meerkat and is being replaced by Shotwell. So, you can install Shotwell as a replacement to F-Spot. There is yet another photo manager called Gthumb but I think Shotwell is the better choice.

Tomboy is a really great note taking application. However, an almost exact clone which can import and use all the notes created by tomboy is available. It is called Gnote. Tomboy can be safely replaced with Gnote. Gnote is a C++ port of Tomboy and claims to be faster. Also, if you use the gnote stable ppa by adding ppa:gnote/ppa to your software sources, you can install gnote 0.7.x which features a nice gnome-panel applet for Gnote.

I don’t know a good replacement for this great game, but it is just a mind teaser game. So, if you can do without it, just remove it.

Following is the step by step procedure for doing this.

Open up Synaptic (System>Administration>Synaptic Package Manager) and click on Settings>Repositories. Make sure “Community maintained open source software (universe)” is selected. Now click Other Software tab and click Add. Then copy/paste the following


and click Add Source. This will add gnote PPA so that you can install the latest version of Gnote. Close the repositories window. Click on Reload so that the software lists are fetched from all repositories.

Removal of Mono and Installation of Alternatives
Search for shotwell and gnote in Synaptic Package Manager and mark them for installation. Search for mono-runtime and mark it for removal. This will ask for your confirmation that several other mono related packages including F-Spot, Tomboy and Gbrainy will be marked for removal. Just confirm it and click on Apply. This should free about 40 MB of Disk Space and download about 3 MB only.
To add Gnote panel applet, press Alt+F2 and type in killall gnome-panel and then when the panel loads back, Right click on it and select Add oo Panel, search for Gnote and click Add.

Other Softwares that depend on mono and alternatives
There are few other great softwares based on mono that are great but aren’t included in the default install. However, lets discuss them too. If you have any of those installed, they will be removed too. So, lets get to their alternatives.

Many Ubuntu users use Mac OS like docks these days. One such great dock is Docky. But there are some other good docks which can serve as a replacement for Docky. One of them is Avant-Window-Navigator. It is not so friendly in terms of disk space though. It consumes over 40MB of disk space and hence defeats the purpose if you are trying to remove mono because of disk space usage. Cairo dock may serve as a good replacement in that case.

Banshee is a popular music player and media management application and favorite gnome media manager for lot of Linux users. However, the default Music Manager Rhythmbox should serve as a good replacement for it for a lot of users. Exaile is also good one.

I never really got used to this application. I primarily used it for Docky (Docky was originally a part of Gnome-do) and never used other features that it had to offer. However, there are some huge fans of this application. It claims to get things done faster in Gnome. There is another application called kupfer (it is not a KDE application as the name suggests, yes I’m talking about its initial letter :D) which claims to to provide similar functionality. It also has a lot of plugins and you should really give it a try. But it does not look sleek as Gnome-do though.

Beagle is a indexing and searching tool for the Desktop. Tracker, Pinot or Google-Desktop-Search should serve as replacements.

Bless Hex Editor
Bless is a GUI hex editor which is really awesome. There is a replacement called ghex for it but it is not as good though.

Muine Music Player
Muine is a simple music player. It aims to be and remain simple music player. I haven’t really used it but I think the default movie player Totem, which can be used as audio player too of course, can provide everything that Muine has to offer.

This one is a graph drawing application written in GTK#. I found a replacement called extcalc (qt3 application) but it is not as simple (which in other words also means it is more powerful and includes more features such as scripting :)).

Tangerine is a DAAP server which can serve music to Apple iTunes, Rhythmbox, Banshee, Amarok, XBMC, Limewire or any other music player that supports this protocol. I haven’t actually used it but there is another package mt-daapd which claims to provide similar functionality.

It is an IRC client. There are several IRC clients that should replace it. I use X-Chat.

Mistelix is a DVD authoring application. I don’t actually do any of that, but according to this article, one or a combination of Q DVD-Author, DVDStyler, DeVeDe, ManDVD, and tovidgui should be able to provide what Mistelix does.

This is a twitter client. The default application Gwibber should be a good replacement for this.

gnome-rdp is a remote desktop client for Gnome. It can be replaced by reminna.

It claims to be a music organizer and tagger. I am assuming EasyTag or Picard should serve as a replacement.

Tasque brings Remember The Milk service (TODO list management) to the Desktop. However, Avant Window Navigator, Screenlets or Deskbar can offer similar functionality with RTM-related plugins.

Blam is an RSS Aggregator. Liferea, Yarssr and many other applications provide this functionality.

DFO (Desktop Flickr Organizer) is a photo manager which integrates with Flickr. I think only Kflickr (KDE Based) comes as close.

Wallpaper rotator for Gnome. Nitrogen and Wally should serve as replacements.

These are easy file sharing applications. BaShare can serve as a replacement.

It is a Desktop Last.fm player. Rhythmbox or lastfm should serve as a replacement.

LAT is a LDAP Administration tool. Luma or GQ can serve as replacements.

It is a simple media information extractor. MediaInfo serves as an excellent replacement.

Bareftp is a FTP client. Filezilla Client, gFTP-GTK and various other GUI FTP clients can replace bareftp.

It is an iPod manager. gtkpod serves as a replacement.

It is a System Information Tool. It can be replaced with Hardinfo. Ailurus also has this feature.

It is a Last.fm stream dumper. lastfmproxy and streamdumper can be used to do the same.

Gnome subtitles is a sub-title editor. SubtitleEditor can serve as a replacement.

Panorama images creation helper. Hugin should be a replacement.

It is a translation application which makes the use of online translators such as Google Translate. freespeak should serve as a good replacement.

Mono is an open source, cross-platform, implementation of C# and the CLR that is binary compatible with Microsoft .NET. If you don’t want to use it but still want to develop C# applications that run on Linux, you can go for dotGNU. But unlike Mono, it is not available from Ubuntu software center or officially supported by Cannonical.

If you want to develop cross platform applications or applications for Linux and don’t want to use Mono, C# is not the language you should go with. A better language may be Java, Python or Vala.

Final Notes
I have tried to list all the applications that may prevent you from removing mono. However, I have not used all the programs that I have listed (at least not used them enough to get used to them or to know what features they offer or even to the extent to know them in any way). So, if you think I have missed a program or an alternative, please let me know via comments.
Thank you for reading.