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.
Related
I am trying to import matplotlib and plotly in my python script to plot a simple distribution. Earlier when I was running the script, it was displaying nothing on the command-line and it seemed that it was simply processing the import statement.
To debug it, I upgraded python using brew install python after that and did a pip install --upgrade pip after that. Using the upgraded pip, I made sure that matplotlib and plotly are installed. But, upon running the script, I am getting the following error on command-line:
$ python script.py
Traceback (most recent call last):
File "script.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python2.7/site-packages/matplotlib/__init__.py", line 110, in <module>
import io
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Expected in: flat namespace
in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
Can someone please help me resolve this issue?
Thanks in advance.
I found a similar SO issue for Selenium. The problem appeared to be a python issue after updating and the solution there was to type hash -r python in the terminal. Worth a try.
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
I'm trying to call a function from the cluster module, like so:
import sklearn
db = sklearn.cluster.DBSCAN()
and I get the following error:
AttributeError: 'module' object has no attribute 'cluster'
Tab-completing in IPython, I seem to have access to the base, clone, externals, re, setup_module, sys, and warning modules. Nothing else, though others (including cluster) are in the sklearn directory.
Following pbu's advice below and using
from sklearn import cluster
I get:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from sklearn import cluster
File "C:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
from .spectral import spectral_clustering, SpectralClustering
File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
from ..utils import check_random_state, as_float_array
File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
from .class_weight import compute_class_weight, compute_sample_weight
File "C:\Python34\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
from ..utils.fixes import in1d
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I'm using Python 3.4 on Windows, scikit-learn 0.16.1.
You probably don't use Numpy+MKL, but only Numpy.
I had the same problem and reinstalling Numpy with MKL
pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl"
fixed it.
Note: update the file to the latest version, possibly 64bit - see the list of available Windows binaries
Problem was with scipy/numpy install. I'd been using the (normally excellent!) unofficial installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Uninstall/re-install from there made no difference, but installing with the official installers (linked from http://www.scipy.org/install.html) did the trick.
I am using anaconda got the same error as the OP, when loading Orange, or PlotNine.
I can't recall when this start to happen.
Tracing the dependency of Anaconda3\Lib\site-packages\scipy\special\_ufuncs.cp36-win32.pyd, libifcoremd.dll and libmmd.dll are missing in DependencyWalk. Searching them in anaconda root directry, they are located in both ICC_RT and one version of MKL package.
Adding Anaconda3\pkgs\mkl-2017.0.3-0\Library\bin to PATH, seems to fix SciPy and NumPy related DLL load failure, the above package starts to work again.
I still don't know how to fix this properly. Apparently the downside is that the MKL package could be updated and versions may change so does the path. In this aspect Its equally inconvenient as adding a non-managed package.
Reinstalling ICC_RT fixed the issue for me, libmmd.dll and the related dlls are automatically copied into anaconda3/library/bin afterwards, which is automatically added into PATH by activate command. All previous numpy/scipy related cant load DLL errors are gone now.
From the error log, it shows that scipy module is the most recent module fails to import
File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
from scipy.sparse.linalg import lsqr as sparse_lsqr
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
from .isolve import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
from .iterative import *
File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
from . import _iterative
ImportError: DLL load failed: The specified module could not be found.
I have the same error that show the same log, the problem'd gone when I uninstall/install scipy:
pip uninstall scipy
pip install scipy
Place this line on top of the python file
from sklearn import cluster
That should do it :))
For me what fixed it were these commands:
pip uninstall sklearn
pip uninstall scikit-learn
pip uninstall scipy
pip install scipy
pip install scikit-learnhere
I had the same issue and solved it by installing/updating the mkl package:
conda install mkl
or
pip install mkl
Just for full information, this also downgraded the following packages:
The following packages will be UPDATED:
mkl: 2017.0.4-h6d528fc_0 defaults --> 2018.0.3-1 defaults
The following packages will be DOWNGRADED:
numpy: 1.11.3-py34_0 defaults --> 1.10.1-py34_0 defaults
pandas: 0.19.2-np111py34_1 defaults --> 0.18.1-np110py34_0 defaults
scikit-learn: 0.18.1-np111py34_1 defaults --> 0.17-np110py34_1 defaults
scipy: 0.19.1-np111py34_0 defaults --> 0.16.0-np110py34_0 defaults
I struggled trying to figure this one out; tried to download and install the (unofficial) Numpy+MKL library from the website (risky/tedious?).
Ultimately found success by:
Login to command prompt using admin rights; how to here: https://superuser.com/questions/968214/open-cmd-as-admin-with-windowsr-shortcut
Uninstall existing/tangled version of Scipy & Numpy
pip uninstall scipy
pip uninstall numpy
Fresh install Scipy & Numpy
pip install scipy
pip install numpy
Run Jupyter notebook; it worked for me.
The message ImportError: DLL load failed: The specified module could not be found
informs that there is failure to identify and source the required DLL(s) to use the scikit-learn library; a fresh install of scipy/numpy probably enables a better routing of DLL connections called from Jupyter notebook code(s).
download microsoft visual c++ distribution
link : https://www.microsoft.com/en-in/download/details.aspx?id=53840
vc_redist.x64.exe
install and run this .exe file in your computer.. the DLL import module error will not appear after this
now it will work fine enjoy :)
I am aware that this exact same question has been asked before. I did follow the instructions given in the answer there, and it didn't solve my problem (and I don't have enough reputation to just comment on the Q or A in that thread). Anyway, here's what's going on:
I try to do:
import matplotlib.pyplot
And in return I get:
Traceback (most recent call last):
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3032, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-eff513f636fd>", line 1, in <module>
import matplotlib.pyplot as plt
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/collections.py", line 27, in <module>
import matplotlib.backend_bases as backend_bases
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/backend_bases.py", line 56, in <module>
import matplotlib.textpath as textpath
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/textpath.py", line 22, in <module>
from matplotlib.mathtext import MathTextParser
File "/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/mathtext.py", line 63, in <module>
import matplotlib._png as _png
ImportError: dlopen(/Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/_png.so, 2): Library not loaded: libpng15.15.dylib
Referenced from: /Users/russellrichie/anaconda/lib/python2.7/site-packages/matplotlib/_png.so
Reason: image not found
My Python version:
2.7.7 |Anaconda 2.0.1 (x86_64)| (default, Jun 2 2014, 12:48:16) [GCC 4.0.1 (Apple Inc. build 5493)]
EDIT:
cel's suggestion worked! I just tried "conda remove matplotlib", "pip install matplotlib", and then "conda install matplotlib", and presto! Man, you have no idea how long this problem has vexed me. Bless you all.
Some python packages link dynamically against native c libraries. After an update of one of those libraries, links can break and give you weird error messages about missing dynamic libraries, as seen in the error message in the question.
Basically, after an update of a native library sometimes you also have to rebuild python packages (here matplotlib).
The above statement is true in general. If you are using conda as your python distribution things are usually less complicated:
For extension packages conda also maintains required c libraries. As long as you use only conda install and conda update for installing those packages you should not run into these issues.
For numpy, scipy, matplotlib and many more I would suggest to try conda search <library name> first to see if there's a conda recipe that matches your needs. For most users conda install <library name> will be a better option than pip install.
To make sure that only conda's version is installed you can do
conda remove matplotlib
pip uninstall matplotlib
conda install matplotlib
Afterwards this issue should not appear anymore.
I ran into this problem as well. I updated my Anaconda-Navigator and the next time I opened a project with matplotlib.pyplot, I ran into a similar problem. What worked for me was:
conda install libpng
I had this problem, but it was because I had set
export DYLD_LIBRARY_PATH="/Users/charlesmartin14/anaconda/lib":$DYLD_LIBRARY_PATH
removing this setting and restarting the shell fixed it
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.
"