How to Install Matplotlib as a Macintosh Yosemite User

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 , this will work fine. I do not know what is happening, and I just got lost. I tried using homebrew, macports installation, dmg installation. I also have very little experience installing things through the terminal, so I just kept track of what other people were saying. Although, this still does not work.

0
source share
2 answers

Mac OS X comes with python by default. And there is one provided by homegrown. I would recommend using homebrew python by default python.

Here, I suspect that your numpy installation has been placed in a package sites directory managed by a non-homebrew package manager, while the matplotlib package is installed in a different site-packages directory. (But I'm not sure). However, this is due to the use of multiple python / package managers. This may not be the best answer, but so far the only solution I can solve to fix your problems is to remove the package and also delete everything in any python site-packages directory that you can find on your file system. And install python again via homebrew and then install all the necessary packages using pip (which installs automatically when python is installed using homebrew)

Warning Be sure to include package names and save the names somewhere before uninstalling 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's a question related to someone who faced a similar problem: Numpy build failed with multiarray unable to import

My advice . Do not use Homebrew and Macports or any other package manager together. They ruined each other, and I faced consequences in the past. I just use Homebrew python. For installing scientific packages, Anaconda or Canopy python packages (choose one) are really useful, which can be installed on top of homebrew ping code.

+2
source

After many problems similar to the ones you describe, using sudo pip install -U matplotlib is great for me.

+1
source

Source: https://habr.com/ru/post/977319/


All Articles