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/
Related
Actually I already installed tensorflow by using
$ pip install tensorflow
and it works well when I use
$ python
Python 2.7.15 (default, Jul 23 2018, 21:27:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import tensorflow
>>>
but when I use python3 on command line
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>
it shows an error, and it shows the same error when I use IDLE
use
pip3 install tensorflow
pip installs to default python directory. pip3 installs to python3
I created virtualenv for few months. And I encountered a problem.
When I activate virtual environment I have access to lib like django :
source virtualenv/jsms/bin/activate
(jsms)local% python
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> exit()
(jsms)local% deactivate
But when I use python from the bin folder I can't access to django :
local% virtualenv/jsms/bin/python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
More strange, when I use python3.4 from the bin folder, I am using python 2.7 :
local% virtualenv/jsms/bin/python3.4
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Do you know a way to access lib directly from python in the bin folder ?
activate is just a bash script, so you can always take a look at the activate file and see what it is doing, but I think what you’re looking for is the env variable PYTHONHOME. I would try:
export OLD_PYTHON_HOME="$PYTHONHOME"
unset PYTHONHOME
virtualenv/jsms/bin/python3.4 --version
For windows, you would use the following code from the activate.bat template:
if defined PYTHONHOME (
set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=
)
I've successfully compiled the caffe library and the python module.
I can do this:
Jamess-Air:~ james$ python2 -V
Python 2.7.10
Jamess-Air:~ james$ python2
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>>
But, bizarrely, this fails:
Jamess-Air:~ james$ python2.7 -V
Python 2.7.10
Jamess-Air:~ james$ python2.7
Python 2.7.10 (default, Jun 19 2015, 15:39:31)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
Segmentation fault: 11
Jamess-Air:~ james$
I cannot understand this at all! Whenever I try to run using iPython notebook I get the same crash.
Any ideas as to what may be causing this, and how I might fix it, or at least get iPython Notebook to use the different python version so I can run this thing?
Thanks!
I have installed numpy and opencv using macports as per these instructions, but when I try import cv or import cv2 I just get the segfault and I have no idea why.
Any suggestions?
$ 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 cv
Segmentation fault: 11
$ 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 cv2
Segmentation fault: 11
Sorry there are so few details, but this is a new computer and I installed macports on it just for this, and these are the only things I've installed with macports, so I have no idea why this isn't working.
Edit: Now I'm More Confused.
Looking through the crash report I found this:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
So, as a shot in the dark, I ran python as super user:
$ sudo python
Python 2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>>
As super user, everything appears to run fine. How is this possible?
If you look closely to the info message of your python command, you will see the difference.
From the buggy one:
$ 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 cv2
Segmentation fault: 11
From the working one:
$ sudo python
Python 2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv
>>>
You have two different versions of Python on your machine which might explain the behaviors you got.
After hitting this problem on OSX 10.11 and trawling through several cases of this problem in various contexts, I realized that this problem happens due to following independent reasons mostly:
conflicting python versions (more than one pythons); solution - uninstall one of them, get the one thats compatible with opencv ("Segmentation fault" during "import cv" on Mac OS)
opencv version issue; solution - get the right version for you Python opencv feature detector causes segmentation fault
issue with your numpy version; solution - uninstall and install numpy again (OpenCV - cannot find module cv2)
I tried all 3 but number 3 solved my issue.
Using
cv2.ocl.setUseOpenCL(False)
at the beginning of the code solved the problem for me.
For me the solution was simply
sudo apt install python3-opencv
and then install pip opencv package
sudo pip3 install opencv-python
or
sudo pip install opencv-python
Note: This was because I have launched a new Aws instance.
I encountered the similar problem.
➜ ~ ✗ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
[1] 41233 segmentation fault python
But if I import numpy first, the problem will go away.
➜ ~ ✗ python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 13:19:00)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import cv2
>>>
I have python installed in two locations, in os default it's 2.6.6 and in /usr/local/bin/python2.7 has 2.7.
I have installed cairo (cairo-1.12.18) via source using configure/make/make install, but it appears to have installed under python 2.6.6. How do I install it for python2.7?
[root#xxxxx ~]# python
Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
>>>
[root#xxxxx ~]# /usr/local/bin/python2.7
Python 2.7.8 (default, Nov 18 2014, 11:15:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cairo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cairo
>>>
Thank you.
Be sure to install it using python 2.7 and not python 2.6 (run make and make install using python 2.7). I assume you use Linux OS so your default Python is 2.7, you can change your default Python but it's not recommended due to several reasons. Please look at this StackOverflow question and answers for more informations:
Two versions of python on linux. how to make 2.7 the default