Problems with Pyplot - python

Whenever I use Pyplot
import matplotlib.pyplot as plt
I got this problem. It shouldn't be installed the right way
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: dlopen(/Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so, 2): Symbol not found: ___sincos_stret
Referenced from: /Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so
Expected in: /usr/lib/libSystem.B.dylib
in /Library/Python/2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.9-intel.egg/matplotlib/_path.so
any ideas on how to solve this problem.

Are you using MAC OSX 10.9? If not, it may be that you've installed the wrong version for your matplotlib. In my case, ScipySuperpack installed the wrong version for me although I followed precisely the instruction for Mac OSX 10.8.
If this is your problem, you may solve it through the steps below:
Download the older version of SpicySuperpack in zip format (in my case, through https://github.com/fonnesbeck/ScipySuperpack/archive/10.8_final.zip#).
Uninstall the old matplolib by typing: pip uninstall matplotlib.
Unzip the downloaded ScipySuperpack, if it has not been unzipped yet.
Go to the ScipySuperpack folder and type: easy_install matplotlib-1.4.x-py2.7-macosx-10.8-intel.egg (use a different file name if this is not the one included in your downloaded ScipySuperpack folder)
Note: If you are using virtualenv, just activate your virtual environment before doing the easy_install.
Hope it helps!

If pip uninstall/install doesn't work, you might even have to go deeper. Do you get the same error with other modules within matplotlib or other modules in general from Python?
My suggestion, as you are on OSX, is to use homebrew to manage the installation of Python and pip and then everything should work much smoother.

Easiest is
pip uninstall matplotlib
pip install matplotlib
You may even have to go further to do the same with numpy.
There is some important information regarding getting matplotlib running on OS-X here most significantly:
"Which python for OS X?
Apple ships with its own python, and many users have had trouble with it. There are several alternative versions of python that can be used. If it is feasible, we recommend that you use the enthought python distribution EPD for OS X (which comes with matplotlib and much more). Also available is MacPython or the official OS X version from python.org.
"

Related

How to install scikit-image when the installation appears broken

I'm a newbie in Python, coming from R, and I'm not a programmer, so please be patient if my question is quite silly or trivial, but I cannot find a solution by myself.
I'm using Python 3.7 in Spyder, in a Windows 10 machine.
I'm following this tutorial, and I've understood that I need the scikit-image module.
I've learned that external package should be imported in the same environment of Spyder, so I'm installing them from Spyder:
! pip install scikit-image
And I got this:
Requirement already satisfied: scikit-image in
c:\users\me\appdata\local\programs\python\python37-32\lib\site-packages
(0.15.0) ...
Same for pillow, networkx, PyWavelets, imageio, decorator, numpy (those I suppose they're the dependencies modules). It seems I've what I need.
So I try the first command of the above mentioned tutorial, that is:
from skimage import data
But the results seems this:
Traceback (most recent call last):
File "", line 1, in
from skimage import data
File
"C:\Users\me\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\skimage__init__.py",
line 124, in
_raise_build_error(e)
File
"C:\Users\me\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\skimage__init__.py",
line 104, in _raise_build_error
%s""" % (e, msg))
ImportError: cannot import name 'geometry' from 'skimage._shared'
(C:\Users\me\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\skimage_shared__init__.py)
It seems that scikit-image has not been built correctly.
But I think that this is important:
Your install of scikit-image appears to be broken. Try re-installing
the package following the instructions at:
https://scikit-image.org/docs/stable/install.html
So I went to that link, but the standard installation is what I tried to do. What am I doing wrong?
Thanks in advance
EDIT1:
I've followed the answer, I've run this:
!pip uninstall scikit-image --yes
Uninstalling scikit-image-0.15.0:
Successfully uninstalled scikit-image-0.15.0
Then
!pip install scikit-image
And the result is that is already satisfied:
Requirement already satisfied: scikit-image in
c:\users\me\appdata\local\continuum\anaconda3\lib\site-packages
(0.15.0)
And same for:matplotlib, networkx, pillow, imageio, PyWavelets, numpy, cycler, kiwisolver, pyparsing,python-dateutil, decorator, six, setuptools
EDIT2:, done in the anaconda prompt, already some package are already satisfied, so I restarted Spyder, and sending:
from skimage import data
Gives a different error:
Traceback (most recent call last):
File "", line 1, in
from skimage import data
File
"C:\Users\me\AppData\Local\Continuum\anaconda3\Lib\site-packages\skimage__init__.py",
line 127, in
from .util.dtype import (img_as_float32,
File
"C:\Users\me\AppData\Local\Continuum\anaconda3\Lib\site-packages\skimage\util__init__.py",
line 1, in
from .dtype import (img_as_float32, img_as_float64, img_as_float,
File
"C:\Users\me\AppData\Local\Continuum\anaconda3\Lib\site-packages\skimage\util\dtype.py",
line 1, in
import numpy as np
File
"C:\Users\me\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\numpy__init__.py",
line 142, in
from . import core
File
"C:\Users\me\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\numpy\core__init__.py",
line 23, in
WinDLL(os.path.abspath(filename))
File
"C:\Users\me\AppData\Local\Continuum\anaconda3\lib\ctypes__init__.py",
line 356, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 193] %1 it's not a valid application of Win32
(the last line is translated by me) that I've searched, but despite is a rather well known problem, I cannot find a solution.
Proposed solution: creating a new (virtual) environment
From the given outputs, I would suggest creating a new environment to encapsulate all packages for your current development.
For help regarding environments together with anaconda you may want to look here or create them within the gui.
Some rational for using virtual environments in general you can find in the documentation.
In short: Environments are an easy way to have separated versions of packages for different projects and you separate your development from the system python installation, which may has different packages.
Why virtual environment in your case?
Currently, it looks like a mix of packages from your system installation, paths like
"C:\Users\me\AppData\Local\Programs\Python..."
and installations of anaconda, with paths from
"C:\Users\me\AppData\Local\Continuum\anaconda3\Lib..."
probably this causes your problem (and probably will cause some more).
Looks like something went wrong when you installed. You may need to reinstall it via:
pip uninstall scikit-image
pip install scikit-image
If there are any errors during the last step (save the output), then post it here. That will give a clue as to what's wrong.
pip uninstall scikit-image
conda install scikit-image
it seems that conda will install some other dependency packets.
And it works for me.
For me this worked:-
pip uninstall scikit-image && pip install scikit-image

cannot import name '_nd_image' - SCIPY

I'm having this problem:
File "C:\IntelPython3\lib\site-packages\scipy\ndimage\filters.py", line 37, in
from . import _nd_image
ImportError: cannot import name '_nd_image'
I was checking in that path and i can't find any module or something called nd_image but i've looked for all the scipy releases and i can't find it too.
Can someone help please? (WINDOWS)
You might be using the older version of scipy with the latest version of python.
You should upgrade scipy to solve the problem by typing below command line.
pip install --upgrade scipy
If you are not using pip in Window, you can use conda or other things.
And actually, you can not find _nd_image.py module. This question might be helpful.

Scipy Import Error; cannot import name NUMPY_MKL

I used python xy recently with an old lib of scipy (0.15). Because I wanted to use Spherical Voronoi, I had to install a more recent version of scipy. For this I used pip and the unofficial distributions for python modules with wheel. The install worked without error messages. But now, if I try to import scipy by code, I get this error message below. I already unistalled whole python packages so far and instead installed anaconda. But the error message is still the same. I checked my registry (Windows 10) - can't find anything suspicious.
Any idea? Thank you!
test.py
1.12.1
Traceback (most recent call last):
File "test.py", line 11, in <module>
import scipy
File "C:\Users\Boss\AppData\Roaming\Python\Python27\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name NUMPY_MKL
Your scipy is built with mkl support and requires mkl support in numpy too. Download numpy from the same site you downloaded scipy (probably Christoph Gohlke's builds). Or if you are using Anaconda use Anaconda packages for both.
Updated - Your error is basically that  numpy+mkl (numpy with Intel math Kernel library) so this is because when you have installed the scipy by precompiled archive, which requires  numpy+mkl but installing numpy using pip won't get you that.
This problem can be easy solved by installation for numpy+mkl from whl file from - http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Old - This is due to the improper installation of numpy, I've had this error few days ago and then I had to install the numpy again. So, upgrade pip and then try installing the numpy whl again. It just worked for me.
Get it here -https://pypi.python.org/pypi/numpy
even this has almost everything - http://www.lfd.uci.edu/~gohlke/pythonlibs/

Python - Numpy install and import Issue

I've used pip to install the module numpy (sudo pip install numpy).This works fine.
When importing numpy for use in my own module i get several the following errors.
Traceback (most recent call last):
File "<pyshell#65>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
I'm assuming the error has something to do with the multiarray.so file. I've tried turning it off and on (uninstall re install) and adding the where pip initially saves the module to python export path
(export PYTHONPATH="usr/local/lib/python2.7/site-packages")
doesn't seem to work.
Using which python in terminal gives me Python 2.7.6**, however I downloaded python 3.5 off of the site.
Issue resolved.
The reason i was having installation issues with pip, was down to the fact (thanks pv) that i was using the command:
"pip install moduleName"
rather than
"pip3.5 install moduleName"
this caused all sorts of complications, because i'm running python 3.5 and the "pip" command is for 2.7.
Thanks again.
FWIW -- and for people in the future who are googling for this error -- I ran into this issue when installing numpy separately via Homebrew. It caused all my installations of Python (via pyenv) to refer to the /usr/local/lib installation of numpy (which is where Homebrew installs it). Uninstalling it via brew uninstall numpy fixed the error.
(I don't remember why I had a homebrew-installed numpy, but oh well)
I encountered the same problem.
I tried many ways like:
$pip uninstall numpy
But that did not fix the problem.
I assume a major reason is that I have anaconda multi-Python environments (I have created both py27 and py35). As a result the PYTHONPATH includes paths for both py27 and py35.
My default python env is py35. So using
$conda install numpy
will install numpy under the anaconda python3.5 path.
When uninstalling the numpy, we are not sure which numpy path is exporting, maybe it is only for my case.
Hence I refer to #Dan Nhuyen's solution.
I uninstall numpy via:
$brew uninstall numpy.
As a result, the extra ambiguous paths is removed. Finally, it works.
What worked for me was to request pip to build numpy from source, instead of using the pre-compiled wheel binary:
pip install --no-binary numpy -r requirements.txt

ImportError: No module named backend_tkagg

I have such imports and code:
import pandas as pd
import numpy as np
import statsmodels.formula.api as sm
import matplotlib.pyplot as plt
#Read the data from pydatasets repo using Pandas
url = './file.csv'
white_side = pd.read_csv(url)
#Fitting the model
model = sm.ols(formula='budget ~ article_size',
data=white_side,
subset=white_side['producer'] == "Peter Jackson")
fitted = model.fit()
print fitted.summary()
After execution of this code I have such errors:
/usr/bin/python2.7 /home/seth/PycharmProjects/osiris_project/PMN_way/start.py
Traceback (most recent call last):
File "/home/seth/PycharmProjects/osiris_project/PMN_way/start.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/lib64/python2.7/site-packages/matplotlib/pyplot.py", line 98, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
ImportError: No module named backend_tkagg
Process finished with exit code 1
I`m using openSUSE and pycharm community edition latest version with installed pandas, numpy, etc
How can i fix this problem?
I've seen this before, also on openSUSE (12.3). The fix is to edit the default matplotlibrc file.
Here's how you find where the default matplotlibrc file lives, and where it lives on my machine:
>>> import matplotlib
>>> matplotlib.matplotlib_fname()
'/usr/lib64/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'
The backend setting is the first configuration option in this file. Change it from TkAgg to Agg, or to some other backend you have installed on your system. The comments in the matplotlibrc file list all backends supported by matplotlib.
The backend specified in this file is only the default; you can still change it at runtime by adding the following two lines, before any other matplotlib import:
import matplotlib
matplotlib.use("Agg") # or whichever backend you wish to use
I use openSuse 13.1 and had the same error "ImportError: No module named backend_tkagg".
I solved it by using this suggestion: http://forums.opensuse.org/showthread.php/416182-Python-matplolib.
I've installed the python-matplotlib-tk package, and now it is working just fine.
E.g. you can use: zypper install python-matplotlib-tk
I tried various solutions, only this works for me:
sudo pip install matplotlib --upgrade
I was able to fix this by putting
import matplotlib.backends.backend_tkagg
above
import matplotlib.pyplot as plt
Note, I received the same error while trying to run an executable generated using Py2exe.
Here is what I got when I ran TheProgram.exe from the command prompt:
>>TheProgram.exe
Traceback (most recent call last):
File "ThePythonScriptToMakeIntoExe.py", line 14, in <module>
File "C:\Python34\lib\site-packages\matplotlib\pyplot.py", line 109, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Python34\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
ImportError: No module named 'matplotlib.backends.backend_tkagg'
I add my answer for those who might encounter this problem using CARLA Simulator.
Using Python 3.6, and installing matplotlib v 2.2.5 solved this problem for me.
To remove matplotlib and install the right version you can run
pip uninstall -r requirements.txt
Then add matplotlib==2.2.5 to the requirement file and run pip install -r requirements.txt --user to install the correct versions.
If you are missing the requirements.txt file, here you are
Pillow>=3.1.2
numpy>=1.14.5
protobuf>=3.6.0
pygame>=1.9.4
matplotlib==2.2.5
future>=0.16.0
scipy>=0.17.0
In case you have different python versions and you would like to use a specific python version using py -<version> will use the right python version.
WARNING: Changing Path variable of the current Python version might be dangerous and specially for linux users it might cause that you can not open the terminal again. This is because different Python versions might not be compatible with the current pip version you are using. If it is too late for you and you already messed up with your terminal you can visit This tutorial to fix your issue.
After all of the fixes you might still get this error:
TypeError: blit() got an unexpected keyword argument 'colormode'
So you might want to edit the live_plotter.py file and remove colormode attribute from all the lines which are passing it to blit() method.
I faced this issue before, I solved it by using an old version of matplotlib which is version 3.0.0
if you don't have this version try pip install matplotlib==3.0.0
hope this was helpful!
I faced this issue while doing live plotting using the 2.2.2 version. Tried the following:
pip install matplotlib==3.0.0 --user
It's still an older version but it worked.
I solved the problem by setting the variable before starting python
export MPLBACKEND=Agg; python3
Taken from here.

Categories