I used pyenv to install pypy in windows bash, then use pip to install matplotlib, but when importing pyplot, I got a RunTimeError
In [1]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-1-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/home/zjshao/.pyenv/versions/pypy-5.3.1/site-packages/matplotlib/pyplot.pyc in <module>()
112
113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
115
116 _IP_REGISTERED = None
/home/zjshao/.pyenv/versions/pypy-5.3.1/site-packages/matplotlib/backends/__init__.pyc in pylab_setup()
30 # imports. 0 means only perform absolute imports.
31 backend_mod = __import__(backend_name,
---> 32 globals(),locals(),[backend_name],0)
33
34 # Things we pull in from all backends
/home/zjshao/.pyenv/versions/pypy-5.3.1/site-packages/matplotlib/backends/backend_tkagg.pyc in <module>()
11
12 # Paint image to Tk photo blitter extension
---> 13 import matplotlib.backends.tkagg as tkagg
14
15 from matplotlib.backends.backend_agg import FigureCanvasAgg
/home/zjshao/.pyenv/versions/pypy-5.3.1/site-packages/matplotlib/backends/tkagg.pyc in <module>()
7 import numpy as np
8
----> 9 from matplotlib.backends import _tkagg
10
11 def blit(photoimage, aggimage, bbox=None, colormode=1):
RuntimeError: Cannot dlopen tkinter module file
In [2]:
So what can be the problem, and how to solve this problem?
Any suggestions would be appreciated!
Perhaps something wrong with your python installation. The best ways is delete python and reinstall.
I suggest you install python from Anaconda. It is 'next-click' installer (awesome for windows) which set python path environment variable, and have useful package pre-installed, including 'mathplotlib'.
Related
I am using python from a anaconda installation and using the python
notebook. From the jupyer notebook (ipython) I import fssa like:
import fssa
I get the following error message (see below).
Any help from you will be appreciated.
I have tried uninstalling and reinstalling scipy, numpy, and fssa and reinstalling
them, but the problem seems to remain.
ImportError Traceback (most recent call last)
/tmp/ipykernel_218856/781571052.py in <module>
----> 1 import fssa
~/anaconda3/lib/python3.9/site-packages/fssa/__init__.py in <module>
82
83 import pkg_resources
---> 84 from .fssa import scaledata, quality, autoscale
85
86 __version__ = pkg_resources.get_distribution(__name__).version
~/anaconda3/lib/python3.9/site-packages/fssa/fssa.py in <module>
46 import scipy.optimize
47
---> 48 from .optimize import _minimize_neldermead
49
50
~/anaconda3/lib/python3.9/site-packages/fssa/optimize.py in <module>
11 import numpy
12 from numpy import asfarray
---> 13 from scipy.optimize.optimize import (OptimizeResult,
14 _status_message, wrap_function)
15
ImportError: cannot import name 'wrap_function' from 'scipy.optimize.optimize'
(/home/debasish/anaconda3/lib/python3.9/site-packages/scipy/optimize/optimize.py)
I got this erreur when I've tried to import scikit learn to my python 3.5 (jupyter notebook):
from sklearn.model_selection import train_test_split
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-139cc3505715> in <module>()
----> 1 from sklearn.model_selection import train_test_split
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/__init__.py in <module>()
55 else:
56 from . import __check_build
---> 57 from .base import clone
58 __check_build # avoid flakes unused variable error
59
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/base.py in <module>()
10 from scipy import sparse
11 from .externals import six
---> 12 from .utils.fixes import signature
13 from .utils.deprecation import deprecated
14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
12 assert_all_finite,
13 check_random_state, column_or_1d, check_array,
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/validation.py in <module>()
16
17 from ..externals import six
---> 18 from ..utils.fixes import signature
19 from .deprecation import deprecated
20 from ..exceptions import DataConversionWarning as _DataConversionWarning
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/sklearn/utils/fixes.py in <module>()
289 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
290 else:
--> 291 from scipy.sparse.linalg import lsqr as sparse_lsqr
292
293
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in <module>()
110 from __future__ import division, print_function, absolute_import
111
--> 112 from .isolve import *
113 from .dsolve import *
114 from .interface import *
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in <module>()
4
5 #from info import __doc__
----> 6 from .iterative import *
7 from .minres import minres
8 from .lgmres import lgmres
/opt/Anaconda/Anaconda3-4.2.0/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
6
----> 7 from . import _iterative
8
9 from scipy.sparse.linalg.interface import LinearOperator
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory
the scikit learn 0.18.2 package is already installed and I can see it on the list when I run conda list(I got the same error with the last version 0.19.1).
I work with the Anaconda 3 (conda 4.2.2)
you'r python installation has missing dynamically linked shared library which is used by scipy.
generally when you install anaconda under lib directory this shared objects are present and respective paths are exported in environment for dynamic linking.
check if this files are there under the lib directory of your anaconda installation.
e.g:-
/anaconda3/lib/libquadmath.0.dylib
if it is not there then please reinstall anaconda it will solve your problem.
if this file exists then please check your environment path. which must have anaconda installation path in there list.
I have Anaconda installed on OS X. I am able to import sklearn from a python terminal and an IPython terminal. But when I try to import sklearn from a Jupyter notebook, I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-8fd979e02004> in <module>()
----> 1 import sklearn
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/__init__.py in <module>()
55 else:
56 from . import __check_build
---> 57 from .base import clone
58 __check_build # avoid flakes unused variable error
59
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/base.py in <module>()
10 from scipy import sparse
11 from .externals import six
---> 12 from .utils.fixes import signature
13 from .utils.deprecation import deprecated
14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
12 assert_all_finite,
13 check_random_state, column_or_1d, check_array,
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/validation.py in <module>()
16
17 from ..externals import six
---> 18 from ..utils.fixes import signature
19 from .deprecation import deprecated
20 from ..exceptions import DataConversionWarning as _DataConversionWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/fixes.py in <module>()
288 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
289 else:
--> 290 from scipy.sparse.linalg import lsqr as sparse_lsqr
291
292
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in <module>()
110 from __future__ import division, print_function, absolute_import
111
--> 112 from .isolve import *
113 from .dsolve import *
114 from .interface import *
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in <module>()
4
5 #from info import __doc__
----> 6 from .iterative import *
7 from .minres import minres
8 from .lgmres import lgmres
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
6
----> 7 from . import _iterative
8
9 from scipy.sparse.linalg.interface import LinearOperator
ImportError: dlopen(/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
Referenced from: /Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so
Reason: image not found
I can import numpy, scipy, and pandas fine from the Jupyter notebook. It is just sklearn that fails.
I have also tried creating a new conda environment (conda create -n test_env jupyter notebook matplotlib scipy numpy pandas scikit-learn), but the error persists in the new environment as well.
I managed to figure out what was going on, so I'll post my solution here in case anyone else runs into the same problem. As it turns out, I had modified the DYLD_FALLBACK_LIBRARY_PATH environment variable in my .bashrc file when I had installed another piece of software. Restoring this environment variable to its default fixed the problem for me.
(Incidentally, scikit-learn was failing to import in a standard Python terminal as well. I didn't initially realize this because I was testing the Python terminal in an environment in which I had accidentally restored the environment variables to their defaults, overwriting the change I had made in my .bashrc file.)
I tried to import matplotlib.pyplot, however received an error relating to python-tk not being installed. It appears to be installed but I still appear to be receiving the error. Any help would be appricated. For further info, the output is below. Many thanks.
$ ipython
Python 2.7.7 (default, Jun 3 2014, 16:16:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy as np
In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-2-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/usr/lib/pymodules/python2.7/matplotlib/pyplot.py in <module>()
96
97 from matplotlib.backends import pylab_setup
---> 98 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
99
100
/usr/lib/pymodules/python2.7/matplotlib/backends/__init__.pyc in pylab_setup()
26 # imports. 0 means only perform absolute imports.
27 backend_mod = __import__(backend_name,
---> 28 globals(),locals(),[backend_name],0)
29
30 # Things we pull in from all backends
/usr/lib/pymodules/python2.7/matplotlib/backends/backend_tkagg.py in <module>()
6 import os.path
7
----> 8 import Tkinter as Tk, FileDialog
9
10 # Paint image to Tk photo blitter extension
/usr/lib/python2.7/lib-tk/Tkinter.py in <module>()
40 import _tkinter
41 except ImportError, msg:
---> 42 raise ImportError, str(msg) + ', please install the python-tk package'
43 tkinter = _tkinter # b/w compat for export
44 TclError = _tkinter.TclError
ImportError: libBLT.2.4.so.8.5: cannot open shared object file: No such file or directory, please install the python-tk package
No such file or directory, please install the python-tk package
Install the package using:
sudo apt-get install python-tk
As a temporary arrangement just do
mv libBLT.2.4.so.8.6 libBLT.2.4.so.8.5
under /usr/lib/ . It should work fine again
See debian bugreport:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=751767
(as far as I know, matplotlib does not depend on "blt")
I am unable to import pylab using the latest version of Anaconda (Linux 64 bit). Other packages seem to work fine. (Note: I don't have sudo access)
In [1]: import pylab as pl
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-2cf12a0af6ff> in <module>()
----> 1 import pylab as pl
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/pylab.py in <module>()
----> 1 from matplotlib.pylab import *
2 import matplotlib.pylab
3 __doc__ = matplotlib.pylab.__doc__
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/pylab.py in <module>()
267 from numpy.linalg import *
268
--> 269 from matplotlib.pyplot import *
270
271 # provide the recommended module abbrevs in the pylab namespace
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
96
97 from matplotlib.backends import pylab_setup
---> 98 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
99
100
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/backends/__init__.pyc in pylab_setup()
23 backend_name = 'matplotlib.backends.%s'%backend_name.lower()
24 backend_mod = __import__(backend_name,
---> 25 globals(),locals(),[backend_name])
26
27 # Things we pull in from all backends
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt4agg.py in <module>()
11
12 from backend_agg import FigureCanvasAgg
---> 13 from backend_qt4 import QtCore, QtGui, FigureManagerQT, FigureCanvasQT,\
14 show, draw_if_interactive, backend_version, \
15 NavigationToolbar2QT
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/backends/backend_qt4.py in <module>()
23 figureoptions = None
24
---> 25 from qt4_compat import QtCore, QtGui, _getSaveFileName, __version__
26
27 backend_version = __version__
/home/josh/installs/conda/1.7.0/lib/python2.7/site-packages/matplotlib/backends/qt4_compat.py in <module>()
34 # Now perform the imports.
35 if QT_API in (QT_API_PYQT, QT_API_PYQTv2):
---> 36 import sip
37 if QT_API == QT_API_PYQTv2:
38 if QT_API_ENV == 'pyqt':
ImportError: No module named sip
If I try
> conda install sip
I get:
Error: No packages found matching: sip
I also get errors with:
$ pip install sip 1
Downloading/unpacking sip
You are installing a potentially insecure and unverifiable file. Future v
ersions of pip will default to disallowing insecure files.
Downloading sip-4.15.2.zip (899kB): 899kB downloaded
Running setup.py egg_info for package sip
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/tmp/pip_build_josh/
sip/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/tmp/pip_build_josh/sip/
setup.py'
----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build
_josh/sip
Storing complete log in /home/josh/.pip/pip.log
Any thoughts on why?
Just had this problem and it was related to which qt backend matplotlib was trying to use, try:
import PyQt4
If you don't have PyQt4 you probably have PySide
import PySide
If this is the case you need to set the matplotlib.rcParams['backend.qt4'] == 'PySide' not 'PyQt4'. You can also do this in your matplotlibrc file (~/.matplotlib/matplotlibrc)
# find and change line:
backend.qt4 : PySide
Note: if you don't have the matplotlibrc file you can copy it from the matplotlib source directory
import os
import matplotlib
mpl_dir = os.path.dirname(matplotlib.__file__)
os.system("cp {}/mpl-data/matplotlibrc ~/.matplotlib/".format(mpl_dir))
Following worked for me
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pylab as pl