Categories
Mac Python

Fixing fatal error: ‘openssl/aes.h’ file not found on OS X

OS X recently started using their own library instead of OpenSSL. So new installations for anything that depends on OpenSSL might fail. If you already have OpenSSL installed on your system, for example using Homebrew, you just need to point to the library while compiling your program.

For example, if you’re trying to install the popular cryptography package from PyPI, you can do these:

The above mentioned package is a common dependency of many other packages, for example Scrapy. So if you encounter an issue like this, try installing that single dependency first and then the dependent package. In this case, first use the above command to install the cryptography package and later install Scrapy.

Categories
Mac Python

Python: Sending Growl Notifications

Growl is an extremely popular notification system for OS X. The application allows developers to display beautiful notification messages with ease. If you’re developing an application in Python and would like to integrate with Growl, this blog post is for you.

Introducing GNTP

Let me quote from the official docs here – http://www.growlforwindows.com/gfw/help/gntp.aspx#intro:

The Growl Network Transport Protocol, or GNTP, is a protocol to allow two-way communication between applications and centralized notification systems such as Growl for Mac OS X and to allow two-way communication between two machines running centralized notification systems for notification forwarding purposes.

In short, GNTP allows two way communication between your application and Growl. Even shorter – you can use GNTP to publish notifications using Growl.

GNTP Binding for Python

We have an excellent library for interacting with GNTP. The project is hosted on Github – https://github.com/kfdm/gntp/ and the docs are available here – http://pythonhosted.org/gntp/

So how to use this library? First, install the library using pip –

To see if the installation was ok, we can test by running the module directly –

Sending Notifications

Sending a quick notification from the Python interactive prompt:

Simple, right?

You can find advanced examples on the github readme and the docs (links above). Have fun with Python and Growl!

Categories
Mac PHP

Mac OSX, nginx and php-cgi: doing it the quick and dirty way!

I usually use Apache and it’s PHP5 module for my day to day php development. However, here came a time, when I needed to work on a project that involved using nginx. Installing nginx was easy with homebrew:

However, the recommended way to use php with nginx is using php-fpm. Since I use the apache module most of the time and building php with fpm builds it “–without-apache”, I didn’t want to go for anything complex for just one project at hand. I knew I could use the native “php-cgi” module, so I just googled, found few tips and set it up.

This is my nginx configuration:

Basically, all I did was change the root element to point to my current “~/Sites” directory which I use as the htdocs for apache. And I’m using unix sockets for better performance. Please read the nginx docs if you don’t understand any of the directives but I’m pretty confident that all of them are more or less self explanatory.

Now, we bind php-cgi to the socket mentioned in our nginx conf file. That’s quite straightforward:

Once we have updated the nginx configuration and started the php-cgi process, we should restart nginx:

This should restart nginx and all files with the “.php” extension will be parsed by php.

If you get “no input file specified”, check your nginx configuration and make sure that the paths are all correct. Specially this one:

Also check that if the root element is defined in appropriate scope for the block to have access to. If you still run along some issues, do a quick google or ask in stackoverflow. And feel free to experiment with different nginx features, specially url rewrites 🙂