How do I install Matplotlib as a Macintosh Yosemite User - python

I am a Macintosh Yosemite user. When I try to import matplotlib I get the following error.
import matplotlib
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import matplotlib
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/matplotlib/cbook.py", line 33, in <module>
import numpy as np
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/__init__.py", line 170, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/numpy/core/__init__.py", line 6, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
When I use from pylab import axis that would work just fine. I do not know what is going on and I am just so lost. I have tried using homebrew, macports installs, dmg installs. I also have very little experience installing things through terminal so I just followed what other people said. Though, that is still not working.

Mac OS X ships with python by default. And there is one provided by homebrew. I would recommend using homebrew python over the default python.
Here, I suspect your numpy installation has landed up in the site-packages directory managed by the non-homebrew pip package manager whereas matplotlib package is installed in a different site-packages directory. (But I am not sure). Nevertheless it has something to do with multiple python's / package managers being used. This may not be the best answer, but so far the only solution I can think of to fix your problems is to uninstall pip and also remove everything in any python site-packages directory you can find on your filesystem,. And install python via homebrew again, and then install all packages required using the pip (which gets installed automatically when you install python using homebrew)
Warning: Make sure you list out the package names and store the names somewhere before deleting them because you will have to install them again.
brew uninstall python
#(ATTN) Uninstall macports and don't use it with brew
#(ATTN) Delete the contents of all python site-packages directories
rm /usr/local/lib/python2.7/site-packages/*
brew install python
# Homebrew comes with its own pip installed
pip install <package1>, <package2> ...
Here is a related question from someone who faced a similar problem:
Numpy build fails with cannot import multiarray
My advice: Don't use Homebrew and Macports or any other package manager together. They mess up with each other and I have faced the consequences in the past.I just use homebrew python now. For installing scientific python packages either Anaconda or Canopy (choose one) are really helpful, which can be installed on top of the homebrew python.

After having a lot of problems similar to the ones you describe, using sudo pip install -U matplotlib worked fine for me.

Related

Unable to import python modules (numpy, scipy, matplotlib)

I've used the following tutorial to install Python, numpy, scipy and matplotlib:
https://penandpants.com/2012/03/01/install-python-2/
I downloaded each and installed by double-clicking. I'm using a Mac with OS X Yosemite Version 10.10.5
When I try to import numpy, scipy and matplotlib in IDLE I get the follow error message:
`>>> import numpy
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper`
Can anyone please explain to me how to resolve this?
Thanks
use terminal and type
sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy
for python3+ use pip3
I can't say for sure what's wrong with your installation, but I suspect it's due to a some PATH-conusion... Python 2.7 and Numpy should be installed on your Mac by default.
If you run the command which python, you'll see which executable the python-commands invokes... is it the same as the one you installed?
If you write python in the terminal, and press tab twice, do you see multiple options of installed python versions?
Alternative method of installation
I prefer the Anaconda Python Distribution, which you can download like the full version or minimal version, which is the one I prefer.
If you install this, you should consider uninstalling the one you just installed.
Here's how to install the mini version:
Download the installer, and run it by opening a terminal in the folder with the installer, and running the command bash Miniconda2-latest-MacOSX-x86_64.sh. This will start the text-based installer, and if you read the instructions on screen, you'll be fine.
Notice that you have to scroll to the end of the licence agreement, before you can write yes when asked to accept the terms stated.
Say yes when it asked you if you'd like it to add Anaconda Python to your path.
Anaconda Python is different from other python distributions in the regard that it comes with it's own package and environment manager conda. With conda you can have multiple versions of Python installed at the same time (or several environments of the same Python version, but with different packages or versions of packages).
To create a new environment with the name py27, which is using Python 2.7, write conda create -n py27 python=2.7 --yes. Once created, activate the environment by source activate py27.
With the new environment now active, install the packages you need by using conda: conda install scipy matplotlib --yes.
I'd also recommend installing Ipython, which is an improved shell, and possibly the Jupyter notebook: conda install ipython --yes and conda install notebook --yes.
Hope it helps.

Anaconda not able to import the packages like numpy, scipy, theano etc

Without installing Anaconda, everything works fine.
That is, I am able to import the above mentioned packages. But after installing Anaconda, I am not able to import the same packages. Here is the error which I get: -
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 199, in <module>
from . import random
File "/usr/local/lib/python2.7/dist-packages/numpy/random/__init__.py", line 99, in <module>
from .mtrand import *
ImportError: /usr/local/lib/python2.7/dist-packages/numpy/random /mtrand.so: undefined symbol: PyFPE_jbuf
Once you install the Anaconda distribution it appends the .bashrc paths with the location of the anaconda/bin.
This means that any python packages installed in the /usr/local/ may not be importable.
I second the suggestion above and recommend using virtual environments to do your work. The Anaconda Python distribution comes with conda package management. This may make your life easier.
You can create a new environments and install packages not provided by the distribution using conda build(http://conda.pydata.org/docs/build_tutorials.html)
Also look at pip and python wheel.

Python cannot import pylab [duplicate]

At some point in the last few days, Matplotlib stopped working for me on OS X. Here's the error I get when trying to import matplotlib:
Traceback (most recent call last):
File "/my/path/to/script/my_script.py", line 15, in <module>
import matplotlib.pyplot as plt
File "/Library/Python/2.7/site-packages/matplotlib/pyplot.py", line 34, in <module>
from matplotlib.figure import Figure, figaspect
File "/Library/Python/2.7/site-packages/matplotlib/figure.py", line 40, in <module>
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
File "/Library/Python/2.7/site-packages/matplotlib/axes/__init__.py", line 4, in <module>
from ._subplots import *
File "/Library/Python/2.7/site-packages/matplotlib/axes/_subplots.py", line 10, in <module>
from matplotlib.axes._axes import Axes
File "/Library/Python/2.7/site-packages/matplotlib/axes/_axes.py", line 22, in <module>
import matplotlib.dates as _ # <-registers a date unit converter
File "/Library/Python/2.7/site-packages/matplotlib/dates.py", line 126, in <module>
from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
File "/Library/Python/2.7/site-packages/dateutil/rrule.py", line 14, in <module>
from six.moves import _thread
ImportError: cannot import name _thread
The only system change I can think of was the Apple-forced NTP update and maybe some permission changes I did in /usr/local to get Brew working again.
I tried reinstalling both Matplotlib and Python-dateutil via Pip, but this did not help. Also tried a reboot. I'm running Python 2.7.6, which is located in /usr/bin/python. I'm running Yosemite (OS X 10.10.1).
sudo pip uninstall python-dateutil
sudo pip install python-dateutil==2.2
I had the same error message this afternoon as well, although I did recently upgrade to Yosemite. I'm not totally sure I understand why reverting dateutil to a previous version works for me, but since running the above I'm having no trouble (I generally use pyplot inline in an ipython notebook).
This problem is fixed in the latest six and dateutil versions. However, in OS X, even if you update your six to the latest version, you might not actually update it correctly. This is what happened to me:
After doing a pip2 install six -U, the new six module was installed in /Library/Python/2.7/site-packages/. However, when I loaded six in a python 2.7 terminal, and checked its path, this is what I got:
import six
print six.__file__
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc
So, python was using an old version of six, which I removed by typing:
rm -rf /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.*
This fixed this issue for me.
Installing the python-dateutil==2.2 did not work for me.
But a quick-and-dirty workaround did work! I replace six.py in python 2.7 with the six.py from python 3.4 (virtualenv). Since, I have the problem in 2.7 but not 3.4.
UPDATE
I had the same problem again after reinstalling python (and after upgrading to El Capitan). Un-obvious thing is that this error occurs only in the IPython shell and notebook (when I do import matplotlib.pyplot as plt) but works fine from a Python shell.
So a better solution (that did work in my case) without a dirty work-around is to force install both six and ipython. Here is what I did to have this fixed :
$ pip install --ignore-installed six
$ pip install --ignore-installed ipython
It is possible that you have a perfectly installed version of any packages you have installed, but the version used by default is not the one you want. You can see the list of paths that python search from in order to find its packages as follows:
>>> import sys
>>> sys.path
In order to let python search first the most updated version of certain package, instead of removing the system version, what can be done is to set the system variable PYTHONPATH in the ~/.bash_profile (or ~/.bashrc if linux) config file to the path where the new packages are installed:
export PYTHONPATH=/Library/Python/2.7/site-packages
An alternative is to modify the python path inside your python script by adding the path at the beginning of the path list:
import sys
sys.path.insert(1,'/Library/Python/2.7/site-packages')
This needs to be done for every script you need a certain package version. You might want for some reason use an older version that you have installed.
BTW all my installations with easy_install, or pip, or from sources go to /Library/Python/2.7/site-packages
This worked en EL Capitan, and now also in macOS Sierra (10.12.2)

python+ pycuda (linux) error

I've installed python+pycuda (and other libraries) through this link: http://wiki.tiker.net/PyCuda/Installation/Linux
But when I run test program, it says:
Traceback (most recent call last):
File "test_driver.py", line 17, in <module>
import pycuda.gpuarray as gpuarray
File "/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/gpuarray.py", line 3, in <module>
import pycuda.elementwise as elementwise
File "/usr/local/lib/python2.7/dist-packages/pycuda-2014.1-py2.7-linux-x86_64.egg/pycuda/elementwise.py", line 34, in <module>
from pytools import memoize_method
File "/usr/local/lib/python2.7/dist-packages/pytools-2014.3.5-py2.7.egg/pytools/__init__.py", line 5, in <module>
from six.moves import range, zip, intern, input
ImportError: cannot import name intern
six is installed. I don't know what should I do!
I was seeing this exact same issue on Ubuntu 14.04 but didn't want to override Ubuntu's version of six due to lots of finicky dependency issues. I thought it was odd that the pytools version in the error message (2014.3.5) didn't match the version from the Ubuntu apt repo (2013.5.7).
It turns out that I had previously tried to install pycuda from source by checking out the git repository. I had also previously installed pip. Since pytools is listed as a requirement in pycuda's setup.py, pip installed its version of pytools (2014.3.5). And that's where the incompatibility between six and pytools originates.
To solve the issue, I uninstalled both pycuda and pytools using pip remove pycuda pytools and then installed pycuda using apt-get which then auto-installed the compatible version of pytools.
Just wanted to post this as an alternative solution in case anyone else prefers to keep the default Ubuntu version of six.
On a OSX system I manage to solve the problem by upgrading the six package via pip. Namely
$ pip install six --upgrade
I had the same error on Ubuntu 14.04 but neither of the tips above worked. This page recommends editing the file causing the error directly. So I edited /usr/local/lib/python2.7/dist-packages/pytools/__init__.py and changed the line:
from six.moves import range, zip, intern, input
Into
try:
from six.moves import range, zip, intern, input
except ImportError:
from six.moves import range, zip, input
Not nice editing included library files, but it got around the error.

scikits.audiolab doen't import into python (numpy.dtype)

I have installed (with lots of troubles) scikits.audiolab for making sounds out of data. Now when I type:
import scikits.audiolab I get the following error
>>> import scikits.audiolab
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/__init__.py", line 25, in <module>
from pysndfile import formatinfo, sndfile
File "/Library/Python/2.7/site-packages/scikits.audiolab-0.11.0-py2.7-macosx-10.7-intel.egg/scikits/audiolab/pysndfile/__init__.py", line 1, in <module>
from _sndfile import Sndfile, Format, available_file_formats, \
File "numpy.pxd", line 30, in scikits.audiolab.pysndfile._sndfile (/private/tmp/easy_install-gKE3i5/scikits.audiolab-0.11.0/scikits/audiolab/pysndfile/_sndfile.c:9632)
ValueError: numpy.dtype does not appear to be the correct type object
How do I fix this?
Any alternative package that can do the job?
I had the same issue and for me it was caused by installing another (more recent) version of NumPy.
Check if you have different versions of NumPy installed and try switching back to an older one. For my part: I had a system-wide installation of Python and common modules like NumPy, which I couldn't touch because I'm not admin on that system. So when I installed some other library locally (in ~/.local/lib/python2.7/) it would also install more recent versions of SciPy and NumPy and put them into that local folder. And when importing the module it would draw from the local directory first before looking at the system-wide libraries which were working fine before with scikits.audiolab. So for me it was solved by
pip uninstall numy && pip uninstall scipy because that only deleted the newer local versions of numpy.
But more specific to your case, here is a tutorial how (on a Mac) to switch to a certain version of NumPy:
multiple numpy version on Mac OS X
The NumPy version I found working for my scikits.audiolab is 1.6.1
>>> import numpy
>>> numpy.version.version
'1.6.1'
Hope that helps. :)
Maybe you installed/upgraded numpy after installing talkbox. Try running this command:
pip install --upgrade --force-reinstall scikits.talkbox
As suggested here:
https://github.com/ppwwyyxx/speaker-recognition/issues/13

Categories

Resources