Archive

Archive for March, 2014

Improving the sidebar of /r/python

March 21, 2014 Leave a comment

In the sidebar of /r/python, there was a very unpythonic infinite loop for a long time:

while 1:
    # do something

Today I sent a message to the moderators and they changed it:

while

Update: I got a message from them.

Categories: python Tags: , , ,

get the command pip3

March 15, 2014 1 comment

Problem
You have Python 2 and Python 3 on the same machine. You want to install a package that requires Python 3. You cannot use the command “pip” because it will install the package as if it were written in Python 2. You want a “pip3” command.

Solution #1 (20140912)

sudo apt-get install python3-pip

Solution #2
I found the solution here.

Steps:

$ wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python3 get-pip.py

Now you have a “pip3” command that you can use to install Python 3 libraries.

Categories: python Tags: ,

installing pgmagick

March 4, 2014 Leave a comment

pgmagick is yet another boost.python based wrapper for GraphicsMagick.

GraphicsMagick is the swiss army knife of image processing. …it provides a robust and efficient collection of tools and libraries which support reading, writing, and manipulating an image in over 88 major formats including important formats like DPX, GIF, JPEG, JPEG-2000, PNG, PDF, PNM, and TIFF.” (source)

Here I found an interesting blog post on how to remove image backgrounds with a Python script (comments on it here). The script uses the pgmagick library.

Problem
How to install pgmagick and GraphicsMagick? That is, the following line shouldn’t drop any error :)

>>> import pgmagick
>>>

Solution
It may not be an optimal solution because it installed on my machine LOTS OF extra packages… However, it worked for me.

$ sudo add-apt-repository ppa:dhor/myway
$ sudo apt-get update
$ sudo apt-get install graphicsmagick

$ sudo apt-get install libmagick++-dev
$ sudo apt-get install libboost-python-dev
$ sudo pip install pgmagick -U

Usage example
scale example (copied from here):

>>> from pgmagick import Image, FilterTypes
>>> im = Image('input.jpg')
>>> im.quality(100)
>>> im.filterType(FilterTypes.SincFilter)
>>> im.scale('100x100')
>>> im.sharpen(1.0)
>>> im.write('output.jpg')

Links

Categories: python, ubuntu Tags: ,