I have mac os x 10.9. I downloaded opencv-python using homebrew and I have both the python 2.7 and python 3.4 versions off of the main python site, downloaded the usual way with macs. I need to use opencv, but they do not have a download package for macs so I used homebrew:
brew tap homebrew/science
brew install opencv
When I type python into the terminal, and then type import cv, I get a segmentation error and python quits unexpectedly. The same thing happens in IDLE. For python 3.4, I get a no module error. Here it is:
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/aurora_alvarez-buylla/cv.py", line 1, in <module>
from cv2.cv import *
ImportError: No module named 'cv2'
Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
Segmentation fault: 11
and then it quits unexpectedly. Does anyone know what is going on? Frankly I have spent way too much time on this opencv issue and am finding it very frustrating. Thank you!
Chris Muktar pointed in this thread that the problem is caused by the conflict between the system Python and brewed Python. Following that idea, I resolved this issue by removing the system python and re-installing opencv:
$ cd /usr/bin
$ sudo mv python python.bak
$ brew uninstall opencv
$ brew install opencv
Related
I have been using lirc in Python 2.7 and Python 3.5.3 on Rpi3. Now I have installed Python 3.8.7 from source code, but I am not able to use lirc in this version of Python, but it still works in Python 3.5. apt-get reports that python3-lirc is already the newest version (1.2.1-2). How to get lirc work in both Python 3.5 and 3.8?
pi#RPi3:~ $ python
Python 3.8.7 (default, Jan 7 2021, 08:59:27)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'lirc'
>>>
pi#RPi3:~ $ python3.5
Python 3.5.3 (default, Nov 18 2020, 21:09:16)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lirc
>>> sockid=lirc.init("myProg", blocking = False)
>>>
It means that you installed lirc on only one of the two pythons.
Use the pip from your Python 3.8 to install lirc so that the module will also be accessible to your Python 3.8.
Module lirc has to be uninstalled with pip, then python-lirc can be installed in Python 3,8 as described in https://github.com/tompreston/python-lirc/issues/26 after installing cyhton with pip.
Have both versions of Python (Legacy 2.7.10 and 3.6.2) installed on macOS Sierra.
Installed pip using the following steps.
Downloaded it using curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Installed pip it by running the installer script:
sudo python get-pip.py
Checked for any upgrades / updates for pip:
sudo pip install -U pip
Installed django 1.11:
sudo pip install django==1.11
When I run python (legacy):
python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.11
However, when trying it using python3:
python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
Note: I followed a different tutorial and got python3 working with django 1.11 using virtualenv - please don't suggest this as I am new to the python world and just want to use python3 / django 1.11 in a non-virtual environment - I just want have it working like the legacy python interpreter is behaving.
pip installs libraries differently for python2 and python3, so you effectively have different environments for each. If you want to install Django for python3, you'll want to install it like this:
pip3 install django==1.11
I recently installed openalpr on my mac using brew install openalpr with success. I would like to use the openalpr library with python 2.7 but I am having difficulty binding the two and could use some help.
I currently get the following in my projects file location:
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from openalpr import Alpr
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named openalpr
>>>
When I move to /usr/local/Cellar/openalpr/2.3.0/lib/python2.7/dist-packages/openalpr
The import works. How can I bind this library? Thanks
EDIT: I think I've seen that running the setup.py for openalpr is how you bind but I have no idea where to find it in my file system.
I had to do the following command:
echo /usr/local/opt/openalpr/lib/python2.7/dist-packages/ >> /usr/local/lib/python2.7/site-packages/openalpr.pth
I'm trying to work with psycopg2 natively on Mac. It installs fine, with no errors at least, but when i import it get an error message.
I've seen dozens of threads with similar issues and solutions that vary massively and just seem excessive for such a common module.
can anyone help?
Last login: Wed Oct 12 15:47:24 on console
Gurmokhs-MBP:~ Gurmokh$ pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /Library/Python/2.7/site-packages
Gurmokhs-MBP:~ Gurmokh$ python
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site -packages/psycopg2-2.6.2-py2.7-macosx-10.6- intel.egg/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site- packages/psycopg2-2.6.2-py2.7-macosx-10.6-intel.egg/psycopg2/_psycopg.so
Reason: image not found
>>> ^D
Gurmokhs-MBP:~ Gurmokh$
I can see some copies floating round from different applications.
I'm assuming i could copy one of these. The above message tells me what is referencing this file, but they do not tell me where they expect to find it. If i knew where it should go i would try this.
bash-3.2# find . -name "libssl.1.0.0.dylib"
./Library/Application Support/Fitbit Connect/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/lib/libssl.1.0.0.dylib
./Library/PostgreSQL/9.5/pgAdmin3.app/Contents/Frameworks/libssl.1.0.0.dylib
./Users/Gurmokh/.Trash/Navicat for PostgreSQL.app/Contents/Frameworks/libssl.1.0.0.dylib
Thanks guys.
#maxymoo I went with your suggestion. I have installed anaconda2. The install updated my path to include /anaconda/bin.
Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i'm able to import this module.
Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
... print "connection made"
...
connection made
>>>
I try to visualize graph with matplotlib in python but I have few problem in my mac (Yosemite 10.10.2). I already installed matplotlib, and I know that I have 2 version of python installed in my computer, which are 2.7.8 and 2.7.6
Using default interpreter which is python 2.7.8, I got this error
dhcPlus-mbp:~ macbook$ python
Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
But if I try this one, it works on terminal. But I can't build straight from my Sublime with Ctrl+B
dhcPlus-mbp:~ macbook$ /usr/bin/python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>>
My question is, how could I change default python interpreter so I can use the 2.7.6 in my environment?
Any help is greatly appreciated. Thank you very much.
This problem solved by removing the extra Python libraries on Mavericks by
sudo rm -rf /Library/Frameworks/Python.framework/