[转]在OS X 中安装boost.python, 使用homebrew

Installing boost and boost-python on OSX with Homebrew

byAdrian RosebrockonApril 27, 2015 inLibraries,Resources

1

I really, really hope that someone finds this resourceuseful. The amount of time I have wasted over the past few months (passively) trying to getboostandboost-pythonto install on my OSX machinevia Homebrewhas been nothing short of excruciating.

Don’t get me wrong, I love Homebrew. And if you are on an OSX machine andaren’tusingHomebrew, then I suggest you stop reading this post and install it right now.

Anyway, like I said, I hope that this post saves other people some time and hassle. And while this post isn’tentirelydedicated to computer vision, it is still very relevant if you are developing computer vision based applications using Python and OpenCV.

Packages such as Spotify’sAnnoyfor Approximate Nearest Neighbor search have direct applications in the Content-Based Image Retrieval (CBIR)/image search engine space.

Update 4 May 2015:Erik Bernhardssonhas released an update to Annoy that removes the dependency of Boost and Boost.Python from Annoy. You can now simply install Annoy using pip:without any extra dependencies.

And libraries such asdlibprovide Python bindings so you can leverage the power of dlib from your Python shell.

Both Annoy and dlib are just two examples of packages that require the use of boost (and boost-python if you want Python bindings).

Anyway, let’s go ahead and get this tutorial started — I’ve definitely wasted enough of my time working with this problem and I don’t want to waste any of yours either!

What is Homebrew?

Homebrewis “the missing package manager for OSX”. It makes installing and managing packagesnotinstalled by the default Apple installation a breeze, in the same manner that Debiandoes.

Note: Comparing Homebrew to apt-get is not entirely fair, but if this is the first time you are hearing of Homebrew, this comparison should suffice.

What is boost and boost-python?

Boostis a collection of peer-reviewed (i.e. very high quality) C++ libraries that help programmers and developers not get caught up in reinventing the wheel. Boost provides implementations for linear algebra, multithreading, basic image processing, and unit testing, just to name a few.

Again, these libraries are peer-reviewed and very high quality. A very large number of C++ applications, especially in the scientific space, rely on the Boost libraries in some way or another.

We also haveboost-python, which provides interoperability between the C++ and Python programming languages.

Why is this useful?

Well let’s say you are implementing an Approximate Nearest Neighbor algorithm (likeSpotify’s Annoy) and you want to provide pure, vanilla Python support.

However, you want to milk every last little bit of memory and CPU performance out of the library, so you decide to implement performance critical sections in C++.

To do this, you would code thesecritical tasks in C++ using boost — and then interface with the Python programming language with boost-python.

In fact, this is exactly what the Annoy package does. While the package is pip-installable, the package requires boost and boost-python so that it can be compiled and installed.

Installing boost and boost-python on OSX with Homebrew

Now that we have some basic terminology down, let’s go ahead and install our packages.

Step 1: Install Homebrew

Installing Homebrew could not be easier.

Just head to theHomebrewhomepage and copy and paste the following code into your terminal:

Installing boost and boost-python on OSX with Homebrew

Shell

1

Note:This blog post was writtenin January 2015. Definitely head to the Homebrew homepage and use the latest install script provided by the Homebrew community.

Step 2: Update Homebrew

Now that you have Homebrew installed, you need to update it and grab the latest package (i.e. “formula”) definitions. These formula are simply instructions on how to install a given library or package.

To update Homebrew, simply do:

Installing boost and boost-python on OSX with Homebrew

Shell

1

$brewupdate

Step 3: Install Python

It’s bad form to use the system Python as your main interpreter. And this is especially true if you intend on usingvirtualenv.

Before we go any further, let’s install Python via brew:

Installing boost and boost-python on OSX with Homebrew

Shell

1

Step 4: Installing boost

So far so good. But now it’s time to install boost.

And this is where you really need to start paying attention.

To install boost, execute the following command:

Installing boost and boost-python on OSX with Homebrew

Shell

1

$brewinstallboost

You see thatflag?

Yeah, don’t forget that — it’s important.

In my case, I figured that boost-python would already be installed, given theflag.

便是不再存在着任何我曾经对你有过的希望。

[转]在OS X 中安装boost.python, 使用homebrew

相关文章:

你感兴趣的文章:

标签云: