I have mentioned Python’s lack of efficient processing for image processing before, but there is a bigger issue, and I am reminded of it every time I leave Python code for a few months. If the code has dependencies, then when I come back to it, one of these dependencies always seems to break. And herein lies Python’s biggest Achilles heels – it dependencies on libraries. Look, there is nothing wrong with external libraries, but a language should not have so many issues. It starts with Python 2 vs. 3… maybe Python 3 should be called something else – Boa? Anaconda? Something else. There is a reason C++ wasn’t named C 2 (although a better name than C++ would have been great).
So this morning I tried to run some code I probably wrote a year ago. First issue? OpenCV wasn’t installed on my machine (obviously I ran the code on my old machine).
ImportError: No module named cv2
Okay, so the problems are compounded by the fact that I can choose from CV2 or CV3… but to install OpenCV I had to first update brew. Then install OpenCV (CV2):
brew update brew install opencv
Okay, fine. Then it told me I had to make more changes if I wanted to actually import cv2:
mkdir -p /Users/username/Library/Python/2.7/lib/python/site-packages echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/username/Library/Python/2.7/lib/python/site-packages/homebrew.pth
Then I tried to run my code, and here’s what I got:
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9 ImportError: numpy.core.multiarray failed to import
Like, are you kidding me? So okay, I thought maybe I need to update numpy? Nope. Apparently there are two versions of numpy on the system (something to do with using pip vs. brew). So thanks to stackoverflow, I figured out I had to run:
sudo easy_install numpy
Now it runs. But I have to tell you , what a hassle! Ultimately maybe there should be an easier way of dealing with these dependencies. That’s probably why writing code in C, or Julia is nice. You can import libraries, but it is easy to do. That and most things that are critically needed are included in the language. Life would be better if numpy were just integrated into the language. At the end of the day, I don’t want to deal with these issues – and it impacts how portable code is. If I post code in Julia, all anyone has to do is have the compiler for Julia installed, and run the code. With Python,, they have to make sure all the dependencies are also loaded.
That’s one of the reasons Python is challenging for novice programmers to use.
P.S. To add insult to injury, now running some code that was working fine before… still is but now one of the other libraries is complaining…
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/scipy/signal/signaltools.py:194: VisibleDeprecationWarning: `rank` is deprecated; use the `ndim` attribute or function instead. To find the rank of a matrix see `numpy.linalg.matrix_rank`. if rank(in1) == rank(in2) == 0: # scalar inputs