Cannot import matplotlib with ipython/jupyter notebook through a virtual environment.
I'm able to import matplotlib just fine using the console. Having seen other SO posts I can't seem to get this set up right.
I followed this to get the separate ipython/jupyter kernel.
When I checked my locations through jupyter I get
six.__file__: '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc'
and
datutil.__file__: '/Library/Python/2.7/site-packages/dateutil/__init__.pyc'
I am not sure these are correct. Main jupyter error below
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-20188fbdb2fd> in <module>()
1
----> 2 import matplotlib.pyplot as plt
3 get_ipython().magic(u'matplotlib inline')
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/pyplot.py in <module>()
27 from matplotlib import docstring
28 from matplotlib.backend_bases import FigureCanvasBase
---> 29 from matplotlib.figure import Figure, figaspect
30 from matplotlib.gridspec import GridSpec
31 from matplotlib.image import imread as _imread
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py in <module>()
34 import matplotlib.colorbar as cbar
35
---> 36 from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
37 from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
38 from matplotlib.legend import Legend
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py in <module>()
18 import matplotlib.colors as mcolors
19 import matplotlib.contour as mcontour
---> 20 import matplotlib.dates as _ # <-registers a date unit converter
21 from matplotlib import docstring
22 import matplotlib.font_manager as font_manager
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/dates.py in <module>()
117
118
--> 119 from dateutil.rrule import (rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY,
120 MONTHLY, WEEKLY, DAILY, HOURLY, MINUTELY,
121 SECONDLY)
/Library/Python/2.7/site-packages/dateutil/rrule.py in <module>()
17
18 from six import advance_iterator, integer_types
---> 19 from six.moves import _thread
20 import heapq
21
ImportError: cannot import name _thread
Ok I fixed this by using the tutorial properly (http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs)
You need to set up a virtualenv, then make sure that you install jupyter within it. I was using the globally installed jupyter.
Then set up the new jupyter kernel (linked above) and everything should work with your virtualenv pointed to correctly
Related
I want to use ModelicaRes to open my Dymola results in python but the import fails.
from modelicares.simres import SimRes
Gives the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In [2], line 1
----> 1 from modelicares.simres import SimRes
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\__init__.py:54
40 __version__ = '0.12.2'
43 # Standard pylint settings for this project:
44 # pylint: disable=I0011, C0302, C0325, R0903, R0904, R0912, R0913, R0914, R0915,
45 # pylint: disable=I0011, W0141, W0142
(...)
52 # These will be available directly from modelicares; others must be loaded from
53 # their submodules.
---> 54 from modelicares.simres import SimRes, SimResList
55 from modelicares.linres import LinRes, LinResList
56 from modelicares.util import (add_arrows, add_hlines, add_vlines, ArrowLine,
57 closeall, multiglob, figure, load_csv, save,
58 saveall, setup_subplots)
File C:\ProgramData\Miniforge3\envs\main\lib\site-packages\modelicares\simres.py:50
48 from itertools import cycle
49 from matplotlib import rcParams
---> 50 from matplotlib.cbook import iterable
51 from matplotlib.pyplot import figlegend
52 from pandas import DataFrame
ImportError: cannot import name 'iterable' from 'matplotlib.cbook' (C:\ProgramData\Miniforge3\envs\main\lib\site-packages\matplotlib\cbook\__init__.py)
I tried DyMat and Buildingspy but I would prefer to use ModelicaRes. Because Buildingspy makes use of DyMat which is quiet old and seems unmaintained.
I also had this issue.
I fixed this in my fork of modelicares here: https://github.com/sede-fa/ModelicaRes
I basically replaced any reference to matplotlib.cbook to numpy to get the iterable function as shown here: https://github.com/kdavies4/ModelicaRes/issues/42
You can install this via pip by doing: pip install git+https://github.com/sede-fa/ModelicaRes.git
I really need some help, as I have gone through all the posts and nothing has worked. I get this error when importing gensim and not numpy (numpy is before and works fine). All I want to do is import gensim and numpy to then run my analysis.
Here is the full error message:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-3f0b98039a34> in <module>()
1 # pip install --user numpy==1.16.4
2
----> 3 import gensim
4 #import numpy
5
~/.local/lib64/python3.6/site-packages/gensim/__init__.py in <module>()
9 import logging
10
---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401
12
13
~/.local/lib64/python3.6/site-packages/gensim/corpora/__init__.py in <module>()
4
5 # bring corpus classes directly into package namespace, to save some typing
----> 6 from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
7
8 from .mmcorpus import MmCorpus # noqa:F401
~/.local/lib64/python3.6/site-packages/gensim/corpora/indexedcorpus.py in <module>()
12 import numpy
13
---> 14 from gensim import interfaces, utils
15
16 logger = logging.getLogger(__name__)
~/.local/lib64/python3.6/site-packages/gensim/interfaces.py in <module>()
17 import logging
18
---> 19 from gensim import utils, matutils
20
21
~/.local/lib64/python3.6/site-packages/gensim/matutils.py in <module>()
17 import numpy as np
18 import scipy.sparse
---> 19 from scipy.stats import entropy
20 import scipy.linalg
21 from scipy.linalg.lapack import get_lapack_funcs
/cluster/apps/python/3.6.4_cpu/lib64/python3.6/site-packages/scipy/stats/__init__.py in <module>()
343 from .stats import *
344 from .distributions import *
--> 345 from .morestats import *
346 from ._binned_statistic import *
347 from .kde import gaussian_kde
/cluster/apps/python/3.6.4_cpu/lib64/python3.6/site-packages/scipy/stats/morestats.py in <module>()
10 sqrt, ceil, floor, array, compress,
11 pi, exp, ravel, count_nonzero, sin, cos, arctan2, hypot)
---> 12 from numpy.testing.decorators import setastest
13
14 from scipy._lib.six import string_types
ModuleNotFoundError: No module named 'numpy.testing.decorators'
What I have tried:
I have tried using the latest version of numpy, and also forcing it to the version 1.16.4 "pip install --user numpy==1.16.4". I have also tried uninstalling and reinstalling both gensim and numpy, but its not working. I am using Python 3.6 and on a cluster. I don't really understand why numpy has no problem being imported, but that this is a problem of gensim.
Can anyone kindly help me out with this?
Thanks a lot!
Best,
Sandra
Here is my basic program I am running with a local jupyter notebook on my computer. I am not sure how to resolve this dll error:
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline
Here is the error message accompanying my code:
ImportError Traceback (most recent call last)
<ipython-input-1-c1680853bc3a> in <module>()
1 import numpy as np
2 import matplotlib as mpl
----> 3 import matplotlib.pyplot as plt
4 #%matplotlib inline
c:\python27\lib\site-packages\matplotlib\pyplot.py in <module>()
29 from cycler import cycler
30 import matplotlib
---> 31 import matplotlib.colorbar
32 from matplotlib import style
33 from matplotlib import _pylab_helpers, interactive
c:\python27\lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
c:\python27\lib\site-packages\matplotlib\artist.py in <module>()
14 import matplotlib
15 from . import cbook, docstring, rcParams
---> 16 from .path import Path
17 from .transforms import (Bbox, IdentityTransform, Transform, TransformedBbox,
18 TransformedPatchPath, TransformedPath)
c:\python27\lib\site-packages\matplotlib\path.py in <module>()
19 import numpy as np
20
---> 21 from . import _path, rcParams
22 from .cbook import (_to_unmasked_float_array, simple_linear_interpolation,
23 maxdict)
ImportError: DLL load failed: %1 is not a valid Win32 application.
Running Python 2.7 and trying to get plotting to work the tutorials recommend the below command.
from matplotlib import pyplot as plt
Works fine when run from the command line
python -c "from matplotlib import pyplot as plt"
but I get an error when trying to run it inside a Jupyter Notebook.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-21-1d1446f6fa64> in <module>()
----> 1 from matplotlib import pyplot as plt
/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py 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
/usr/local/lib/python2.7/dist-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
/usr/local/lib/python2.7/dist-packages/ipykernel/pylab/backend_inline.py in <module>()
154 configure_inline_support(ip, backend)
155
--> 156 _enable_matplotlib_integration()
/usr/local/lib/python2.7/dist-packages/ipykernel/pylab/backend_inline.py in _enable_matplotlib_integration()
152 backend = get_backend()
153 if ip and backend == 'module://%s' % __name__:
--> 154 configure_inline_support(ip, backend)
155
156 _enable_matplotlib_integration()
/usr/local/lib/python2.7/dist-packages/IPython/core/pylabtools.pyc in configure_inline_support(shell, backend)
359 except ImportError:
360 return
--> 361 from matplotlib import pyplot
362
363 cfg = InlineBackend.instance(parent=shell)
ImportError: cannot import name pyplot
The following command works
import matplotlib
But the following gives me a similar error
import matplotlib.pyplot
You can also use the %matplotlib inline magic, but it has to be preceded by the pure %matplotlib line:
Works (figures in new window)
%matplotlib
import matplotlib.pyplot as plt
Works (inline figures)
%matplotlib
%matplotlib inline
import matplotlib.pyplot as plt
Does not work
%matplotlib inline
import matplotlib.pyplot as plt
Also: Failure to import matplotlib.pyplot in jupyter (but not ipython) seems to be the same issue. It looks like a recently introduced bug in the ipykernel. Maybe someone mark this or the other question as duplicate, thx.
Although this has come up as a topic before it has not been answered. I get the following import error I have just installed canopy from EPD and after I installed it, it keeps coming up with the following error:
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.
[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/IPython/core/shellapp.pyc in <lambda>(key)
231 shell = self.shell
232 if self.pylab:
--> 233 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
234 key = self.pylab
235 elif self.matplotlib:
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_pylab(self, gui, import_all, welcome_message)
2980 from IPython.core.pylabtools import import_pylab
2981
-> 2982 gui, backend = self.enable_matplotlib(gui)
2983
2984 # We want to prevent the loading of pylab to pollute the user's
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
2941 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
2942
-> 2943 pt.activate_matplotlib(backend)
2944 pt.configure_inline_support(self, backend)
2945
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in activate_matplotlib(backend)
285 matplotlib.rcParams['backend'] = backend
286
--> 287 import matplotlib.pyplot
288 matplotlib.pyplot.switch_backend(backend)
289
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
22
23 import matplotlib
---> 24 import matplotlib.colorbar
25 from matplotlib import _pylab_helpers, interactive
26 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
27 import matplotlib.artist as martist
28 import matplotlib.cbook as cbook
---> 29 import matplotlib.collections as collections
30 import matplotlib.colors as colors
31 import matplotlib.contour as contour
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
21 import matplotlib.artist as artist
22 from matplotlib.artist import allow_rasterization
---> 23 import matplotlib.backend_bases as backend_bases
24 import matplotlib.path as mpath
25 from matplotlib import _path
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
48
49 import matplotlib.tight_bbox as tight_bbox
---> 50 import matplotlib.textpath as textpath
51 from matplotlib.path import Path
52 from matplotlib.cbook import mplDeprecation
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
9 from matplotlib.path import Path
10 from matplotlib import rcParams
---> 11 import matplotlib.font_manager as font_manager
12 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
13 from matplotlib.ft2font import LOAD_TARGET_LIGHT
/home/rhys/Documents/Uni_work/Year_2_research_placement/User/lib/python2.7/site-packages/matplotlib/font_manager.py in <module>()
51 import matplotlib
52 from matplotlib import afm
---> 53 from matplotlib import ft2font
54 from matplotlib import rcParams, get_cachedir
55 from matplotlib.cbook import is_string_like
ImportError: libpng16.so.16: cannot open shared object file: No such file or directory
I have tried reinstalling matplotlib but it still comes up with the error and I cannot find the libpng16.so.16 file in \usr\local\lib, can anyone help?
Check Canopy's Package Manager. Make sure matplotlib 1.3.1-8 package is installed.
An older version of matplotlib could be installed. Check the updates section and update your canopy.