Category: Apple

Installing libmagic in Mac OS X (for Python-magic)

When trying to install python-magic I found out that libmagic was not installed (or not properly available) in Mac OS X 10.7 Lion. There was little information on this problem on the Internet so I thought it might be helpful if I briefly wrote down my experiences.

When installing python-magic:

pip install python-magic

there was an error reported by ctypes (a depency that is installed as well). As ctypes should be part of your python (since 2.5) you can ignore this error or install python-magic from this updated version on GitHub: https://github.com/ahupp/python-magic

After the installation completes however, python-magic gives an error (libmagic not available):

>>> import magic
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "[...]/python-magic/magic.py", line 128, in <module>
    raise ImportError('failed to find libmagic.  Check your installation')
ImportError: failed to find libmagic.  Check your installation
>>>

The easiest way to install libmagic is through Homebrew, a Mac package manager. I used to resort to Fink or Macports in the past, but Brew seems a lot cleaner and more straightforward. Install Homebrew according to the instructions and then install libmagic:

brew install libmagic

Brew installs libmagic in /usr/local/Cellar/ . Python-magic however seems to be looking for a reference to libmagic in /usr/local/lib/

To solve this last problem we can create a symlink in /usr/local/lib to the right file.

cd /usr/local/lib/
ln -s ../Cellar/libmagic/5.04/lib/libmagic.dylib libmagic.dylib

After this, python-magic is able to find libmagic and works properly.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon
22 July 2011 • Apple, Geek stuffComments (2)Permalink

Microsoft desperately needs a darn good strategy

Most people who can be considered real geeks are often not Microsoft fans. They are either open source fans and usually have their own personal preference for a version of Linux, or they prefer Apple's products (and thus use Mac OS X). Of late the amount of Apple fanboys (or girls) seems to be increasing. Apple is known for always having had an incredibly loyal following but they now have been converting the masses with their iPod, iMac, Macbook, iPhone and iPad success spree. That has lead them to make serious inroads against their 'big' rival, Microsoft.

Microsoft has been 'under attack' for a while now. Not only by Apple but by some other companies (notably Google) as well. The question is, 'how is Microsoft going to defend (or expand) itself'? Mobile computing devices are seen as the new PC, yet Microsoft has a rather weak presence there. People all around us are sporting iPhones, iPads and Android devices and are getting accustomed to new software (Apps) and interfaces. On most of these mobile products, Microsoft does not exist at all.

recent article on how the CIO of Starbucks roughly said that Microsoft really needs to 'pull a rabit out of its hat' with the next version of Windows, really got me thinking about Microsoft's overall strategy.

In the enterprise software market it might still be all about dotNet (.Net), MS-SQL databases and perhaps SharePoint. In our private lives it is more about: iPhones, iPad, Android, WhatsApp, Ping (chat), Gmail, Twitter, Facebook, Spotify or Last.fm, iPhoto or Picasa, Dropbox, iTunes and Netflix, etc.

Microsoft's strongest products are still its Windows operating system and its Office suite. In other areas, they have strong products too but there are alternatives. Windows is still the most common OS but it does not really exist outside PCs and Mac OS X is making strong headways (especially for home users). Windows 7 is a fine version of Windows but it is still Windows. Is it that different from Windows 95/98 in terms of usability and user experience?

Are Apps the way forward?

The recently announced Mac OS X 10.7 Lion (and even sooner the current 10.6 Snow Leopard version) will have an App store just like the one on the iPhone and iPad where you can buy and download Apps (or get free ones) for your computer. The new Macbook Air is trying to bridge the gap between the iPad and a laptop which essentially means that Apple is trying to incorporate the successes of iOS into Mac OS (bringing the two closer together). When Google launches the Chromium Operating System it will surely have some integration with Android and the Android App store.

Microsoft does not have an App store (of any meaning) and it does not seem to have a clear strategy for integrating one in Windows either. Microsoft Live Mail (formerly Hotmail) does not work as well on an iPhone or Android device - so many people switch to Gmail.

Microsoft Office

The basic Office suite (Word, Excel, PowerPoint) is what I still consider Microsoft's greatest products. There are alternatives but they also have their drawbacks and everyone is - generally speaking - still using Office so from the compatibility perspective it is easier to use Office (in the corporate world). Outlook is the number one corporate e-mailprogram (and calendar) in combination with MS Exchange. The question remains whether Microsoft can uphold that strength and whether the succes of Office is totally dependent on the success of Windows (i.e. can they decouple)?

Where is the strategy?

I am at loss what Microsoft's strategy is. As a consumer I am starting to see little use for Microsoft products. I prefer to use Word and Excel for Word processing and financial or tabular data most of the times. At the same time, I am almost as comfortable using Apple's iWork software and Google Docs. I do not need Windows (as a Mac user) at home. If I did own a PC, I might switch to Ubuntu Linux.

Professionally, I am forced to use Microsoft products. I do not see that changing in the near-near future. My point is however: Microsoft's dominant position in the corporate world is changing. Microsoft's products are starting to seem like products in decline. What we use at home is slowly making it's way into our professional life as well. From Google Chrome to privately purchased (but brought to work) iPads.

What is Microsoft's strategy? Where is their sense of the future? Windows Phone 7 might prove to be a small succes but it is not going to kick-ass like the iPhone and Android do.

Let's end this post with another simple question: Why on earth has Microsoft not developed a version of Office (Word, Excel and PowerPoint at the least) that works on iOS (iPad and iPhone versions), Android and RIM Blackberry OS? From what kind of strategy perspective did they decide to miss that opportunity and risk the most powerful dominance they have (the Office productivity one). Simply put: there is no market leading, kick-ass program that can view and edit Word, Excel and PowerPoint files and runs on all major mobile platforms. (I do not like Documents to Go that much).

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon

Installing PIL in Snow Leopard (_jpeg_resync_to_restart error)

In earlier posts I talked about my troubles with getting my Snow Leopard (Mac OS X 10.6) system fully equipped for work purposes:

In the latest (and hopefully last) part of that saga, I tried to tackle a misbehaving Python Imaging Library (PIL) today. Earlier, I had already spent some hours trying to fix this problem but today I finally managed to overcome this problem. There are plenty of articles/blog posts already covering this problem and going over the installation steps. However, no matter how I followed these steps, it would not work.

I discovered the problem when trying to upload a picture through the Django Admin pages and received a standard Django error template stating that "The _imaging C module is not installed". Digging into this problem a little deeper I found that import the imaging library lists an error. Try this in your terminal:

 

brambraakman$ python
Python 2.6.1 (r261:67515, Jul 7 2009, 23:51:51)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging

This lead to an error that goes something like this:

>>> import _imaging

File "", line 1, in
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so, 2): Symbol not found: _jpeg_resync_to_restart
Referenced from: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so
Expected in: dynamic lookup

Obviously there was something wrong with the jpeg support (libjpeg) in the imaging library. This _jpeg_resync_to_restart error has been encountered by many others as well:

However, whatever way I tried installing libjpeg (download) and PIL, nothing was working. I also had a libjpeg version installed through Fink but the PIL installation never referenced that.

Running:

otool -L /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL/_imaging.so

will give you an overview of the dependencies of _imaging.so. It should return a reference to the libjpeg library.

Solution

I will not repeat the installation instructions for libjpeg and PIL again (you can find them in the links above). In the end I ended up using the new jpeg-7 library and using these instructions for installation.

What was wrong with my installation?

It turned out that the changes I made to install MySQLdb succesfully on my system had caused this problem. I had added:

export CC="gcc-4.0"
export CXX="g++-4.0"

to my .bash_profile which forces the system (at least that is how I understand it) to use an older version of the gcc compiler. Somehow this caused libjpeg (or PIL) to install incorrectly. Removing those lines from my .bash_profile and reinstalling libjpeg and PIL (for the nth time) finally resolved the problem.

Disclaimer
I am relatively new to Mac OS X (and UNIX based programs and libraries) and might sometimes make mistakes that I am unaware of. The above fixed the problem for me and could very well be affecting your system as well. That does not mean that you should take my advice as expert advice or that what I think are related steps and solutions are always correct. You are welcome to correct (and educate) me by leaving a comment.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon
17 October 2009 • Apple, Django, Geek stuffComments (7)Permalink

Installing MySQL, Python, MySQLdb on Snow Leopard (Mac OS X 10.6) for Django

After spending an considerable amount of time installing MySQLdb on Mac OS X 10.5 Leopard, I had to repeat a similar exercise today. I am no expert at this kind of thing whatsoever. Still, I thought it might be useful to share my experiences with you. Snow Leopard Mac OS X 10.6

I let Snow Leopard (NY Times review) in into my house last friday (August 28th, 2009) and the upgrade process (from Leopard) went really smoothly. Apart from a few programs not working anymore, most notably Cyberduck (which needed updating to a newer version), I did not notice any problems. The only worries I had about this update was my Django developer setup: Python, MySQL and some Python modules/libraries.

MySQL needs to be 64 bit

When I tested one of my Django projects, the first thing I noticed was that MySQL was not working properly anymore. I could not get MySQL to start from the PrefPane setting (under System Preferences). I turned out that Snow Leopard requires a 64 bit version of MySQL.
Solution: Download the 64 bit version of MySQL (there are Mac OS X packages (get the one for 10.5 - x86_64) on MySQL's website).

For more information see: Upgrading to Snow Leopard (Ruby on Rails) and Compiling MySQL on Snow Leopard - Hivelogic (if you like to go Pro).

MySQLdb installation

The next "bump" in the road was MySQLdb. This Python DB API is needed to let Python (and Django) interact with MySQL properly. Since I installed (compiled) MySQLdb for the 32 bit version of MySQL, I had a hunch this one was not going to work anymore either. The first thing I tried was simple reinstalling MySQLdb (see Installing MySQLdb for more information). The installer was not too happy however and kept throwing error messages at me.
Solution: First, make sure you have the GCC compiler installed. You can install Xcode (Apple's developer software) for this. You can download this from Apple, but I remember spotting it on the Snow Leopard DVD (Optional Installs). However, it turned out that GCC has been updated by Apple and somehow my MySQLdb installer did not seem appreciate that. Eventually I got this working, but I am not even sure how. One possible solution might have been adding to my .bash_profile:

export CC="gcc-4.0"
export CXX="g++-4.0"

Adding the Mac OS X 10.4 option from the Xcode installer (from the DVD) was also a necessary step.
Now I finally got the MySQLdb install to complete. Unfortunately that did not change anything for me. From the message that MySQLdb reported when imported in the Python shell, I understood that it was still running the 32 bit version (seeing the i386 in the site-packages name of MySQLdb during the install, also alerted me to this).

Python installation

I upgraded my Python installation on Leopard to Python 2.6.1 because I did not want to work with the older Python version that shipped with Leopard. Hopefully, I had assumed that Snow Leopard updated this Python installation (which was not the "System" installation) but it turned out that it did not. My Leopard installed Python was a 32 bit version and I suspected that this was the reason for me being still "stuck" with a broken setup.
Solution: I removed the $PATH settings from my .bash_profile so that the "Python" command would not point to the 32 bit Python anymore. After restarting the Terminal, Python referred to the "system" version of Python again (the one that shipped with Snow Leopard) and that was the 2.6.1 64 bit Python. With this Python I reinstalled MySQLdb, which now compiled to the 64 bit version. And it all worked!

I was not completely out of the woods yet because the Python installation I was now using did not have any of my other modules installed: Django, PIL, Django pagination, etc. Reinstalling those was not too hard though (download, unpack, "sudo python setup.py install").

Yes, there is a price to pay if you always want to run the newest and shiniest software. Especially if you do not always know exactly what you are doing (like me). Next year, with Mac OS X 10.7, we will see what happens again.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon

Installing MySQLdb on Mac OS X Leopard

After many frustrating hours I finally managed to install MySQLdb for Python on my new Mac machine.

What went wrong? I made the mistake of installing a 64 bit version of MySQL 5.1 a couple of weeks ago. Python, however was build in 32 bit. There are many website dealing with this problem (see here and here) but it still did not seem to be solvable for me. After trying reinstalling the 32 bit MySQL and playing around with Fink (a package installer for Mac OS) I was about to try and start off from scratch. It turned out that even though I deleted the 64 bit MySQL and deleted the Fink MySQL package, some residual files where still left on the system. After removing all of the MySQL versions (both the Fink version in /sw/share/ and the MySQL package installed ones in /usr/local/mysql; /usr/local/mysql-version..) and reinstalling the right package one more time, I finally got MySQLdb too work. Here is moment of triumph:

Terminal Windows - MySQLdb install successful

The upside of my hours "wasted": I got to learn a little bit more about bash, building and compiling and setting colors on the terminal window.

  • Enjoyed this post? Please share it with others:
  • del.icio.us Favicon
  • Digg Favicon
  • Facebook Favicon
  • Google Favicon
  • LinkedIn Favicon
  • Reddit Favicon
  • Technorati Favicon
  • TwitThis Favicon
Page 1 of 1 pages