installing opencv for python 2.7 on a MAC - python

I installed opencv via the command pip install opencv-python and then when I import cv2 in python I get the error ImportError: dlopen(/Library/Python/2.7/site-packages/cv2/cv2.so, 2): Symbol not found: _clock_gettime
I would like to install opencv for python 2.7 on a mac. How can I resolve this error ? I am using El Capitan.
I installed opencv prior to this using brew install opencv but then I uninstalled it using brew uninstall opencv before using pip.

This works !
sudo pip install opencv-python==3.3.0.10
El Capitan has an issue detailed here http://answers.opencv.org/question/182067/import-cv2-throws-symbol-not-found-_clock_gettime/
In order to circumvent this issue, I rolled back to an earlier version of opencCV.
A trick to check the available version with pip do
sudo pip install opencv-python==
This will return all the available version and then you can try the ones that work for you.
Dont forget to pip uninstall when moving to a different version

It looks like this is an issue with python-opencv and the mac operating system That you are using. From the link below it looks like Apple changed something to do with _clock_gettime function, meaning the maintainers of python-opencv will need to update.
The commenters on the post below managed to fix the issue by upgrading to Sierra
http://answers.opencv.org/question/182067/import-cv2-throws-symbol-not-found-_clock_gettime/

Related

Uninstalled opencv-python but still able to import cv2. How is this possible?

Tl;dr - after I had an issue with clashed versions between opencv and QT, I uninstalled opencv-python. But somehow I am still able to import and use cv2 inside python. How is that possible? What am I missing? Where is this opencv-python still installed?
Some more details:
My tech spec: Ubuntu 18.04, Python 3.6, PyCharm Community 2020.3.
My actions:
uninstalled opencv: pip3 uninstall opencv-python (process was successful)
validated it was indeed uninstalled: pip3 freeze | grep opencv-python (return nothing)
validated also inside PyCharm that my environment does not have the package installed (I only work with my environment but just to make double-sure...)
To my surprise:
Inside python, import cv2 is a success, and I am able to use all functionality (well, at least the ones I tested...)
=> My question: how is this possible?
After many frustrations, I found the answer - according to this, on Ubuntu the opencv-python installation is with apt-get:
sudo apt-get install python-opencv
Indeed I have python-opencv installed with apt-get.
The error I initially had, with the clash between the opencv and QT - was actually caused by my additional pip installation of opencv.
Conclusion - on Ubuntu, DO NOT use pip install opencv-python!
A question is remained to be asked why it is allowed to make this installation, but that's probably for another day...

Pillow is installed, but still getting "ImportError: No module named PIL"

I did find this question asked by few more people, but none of those exactly met my situation, so asking here myself.
I've (rather had) two versions of Python (2.7 and 3.4.3) on my Mac running the latest MacOS High Sierra. As I understand, the v2.7 comes as default installation with the MacOS. And I installed the 3.4.3 (from .dmg file downloaded from the python site). Thus now, the python command defaults to the 2.7, while python3 points to the 3.4.3 in the terminal.
While trying to learn, I tried a python script that uses
import PIL and from PIL import Image
But when running, this gave the error ImportError: No module named PIL.
Upon research on google, I figured out to install PIL and Pillow using
sudo pip install Pillow
It installed correctly, but I'm still getting the same error.
To remove the confusion, I decided to remove the python 3.4.3 from the system. But even after it's removed, I still get the same error.
Even pip list displays Pillow 5.1.0 alright.
So right now, I've only Python 2.7, and the error persists, while Pillow is also in there.
which python gives /opt/local/bin/python as the path.
Does any of the above ring a bell? Any ideas, what else could be missing here?
Phew, finally found the issue. Thanks #Yash for the pointers.
Incidentally I did a which -a python and surprisingly got this output:
/opt/local/bin/python
/usr/bin/python
Damn, I don't remember when I installed a second 2.7 version on the /opt/local/bin folder (probably via macports). Alright, removed the confusion, deleted this python, so now I'm left only with the system installed python at /usr/bin.
And now the imports all run perfectly fine as expected. :-)
Try this,
sudo pip install image
I hope it works! One more thing, do check if you're running python3 filename.py instead of python filename.py, if you want to install it for Python 3, run the command,
sudo pip3 install Pillow
Basic Installation:
pip install Pillow
Windows Installation:
pip install Pillow
Reference: https://pillow.readthedocs.io/en/stable/installation.html
Try this. It worked for me
pip install --upgrade --force-reinstall pillow
If you get something like access denied error run the below command
pip install --upgrade --force-reinstall pillow --user

What is the deal with `pip install opencv-python` is it a full opencv?

I thought the quickest way to get opencv running in my environment would be as simple as.
sudo pip install opencv-python
It seemed to work properly, I could import
import cv2
img = cv2.imread("a.jpg", 0)
but any other functions as "cv2.SURF" or even "cv2.imshow" are not loaded. So the pip install is giving just a basic opencv?
This issue was solved here
Opencv-python is not official. I tried to install it in a macbook running Ubuntu and, as you, I could import cv2, but some functions were not working.
From the opencv-python website:
MacOS and Linux wheels have some limitations:
video related functionality is not supported (not compiled with
FFmpeg) for example cv.imshow() will not work (not compiled with GTK+
2.x or Carbon support)
Now you might have problems trying to install the official opencv. You have to completely uninstall opencv-python before you attempt to install opencv.
This post is aging. I have Anaconda, and I have installed OpenCV as
conda install -c- conda-forge ffmpeg
pip install opencv-python
Maybe opencv-python had problems before, but now, is funcional
In the OpenCV docs, it is mentioned that sudo pip install opencv-python is an unofficial package for python.
Quote : This package contains only the OpenCV core modules without the optional contrib modules.
It is meant for OpenCV Python bindings only. Additionally, some functions still don't work for MacOS and Linux (cv2.imshow as you mentioned).
If you want the full installation, follow the steps here.
Suggest you to install Anaconda and use its package manager conda to install OpenCV 3.2.0 for linux-64, including OSX. The installation command is conda install -c menpo opencv3=3.2.0.
Checked the OpenCV 3.2.0 package available in Anaconda repository. It includes the features2d.so which is the extra module in opencv_contrib for supporting SIRF.
See this SO Answer for some more information.

Error with igraph library - deprecated library

I have changed my computer to a Linux Mint x64 OS and I have throubles with a python library, igraph library, when i try to execute and old program I made.
DeprecationWarning: To avoid name collision with the igraph project, this visualization library has been renamed to 'jgraph'. Please upgrade when convenient.
I can't find information about how to change my code for the new library.
On a Win8 PC, via pip installation, it works perfectly but I can't make it working on my PC with Mint.
The normal installation made with
sudo apt-get install python-igraph
install 0.6.5-1 library version.
I've also tried installing it with pip but it gives me same error
but installed version is igraph-0.1.11-py2.py3-none-any.whl
I'm using only Graph class
from igraph import Graph
What have I to do to change my code to make it working with the new library? Am I missing something?
edit: it's working on my laptop with Mint x86 OS, library version 0.6.5-1
I think you have installed the wrong igraph libray.
This igraph(0.1.11) is the one you installed, while this igraph(0.7.1) is the one you need (and the well-known iGraph).
Using pip (once you've installed it), Just do:
sudo pip uninstall igraph
Then install the python-igraph-0.7.1 package, using either pip or apt-get as mentionned in comments below:
sudo pip install python-igraph
Hope it works.
sudo -H pip uninstall igraph
then:
sudo pip install python-igraph
worked for me.

Upgraded to Maverick. Can't access my website's server. Python 2.7 and Django framework

I can't access my websites server ever since I upgraded to Mac OSX Mavericks. Whenever I try running the server, I get this message:
ImportError: dlopen(/Library/Python/2.7/site-packages/PIL/_imaging.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/PIL/_imaging.so: mach-o, but wrong architecture
I'm using python 2.7 and django framework. I've been stumped on this error for a long time. Does anyone have a solution for this?
This is a Mavericks issue. Either:
Stop using Mavericks
reinstall pillow or PIL like this:
sudo CFLAGS=-Wunused-command-line-argument-hard-error-in-future pip install pillow
(or just PIL, as you prefer)
Reinstall PIL, or, better yet, install Pillow:
sudo pip install pillow
EDIT: Not sure why there's a downvote.
But, as ubadub suggested, there's an environment variable you can set (ARCHFLAGS, not CFLAGS) to fix the issue in Pillow. You can read more about it here. The short version is that it looks like you should run
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pillow
You should probably pip uninstall pillow first so that it can be reinstalled.
If that doesn't fix your problem, you should follow the advice in this thread, and run
ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /usr/local/include/X11
xcode-select --install
Then uninstall and reinstall pillow.

Categories

Resources