I have the Enthought Canopy installed on my Ubuntu 14.04. I'm trying to run sample matplotlib programs (from the library's website). Every attempt of running the program makes the Canopy's command prompt display following message:
TypeError Traceback (most recent call last)
/home/guras/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
202 else:
203 filename = fname
--> 204 __builtin__.execfile(filename, *where)
/home/guras/Python programy/pierwszy.py in <module>()
4 This example uses the Fahrenheit and Celsius scales.
5 """
----> 6 import matplotlib.pyplot as plt
7 import numpy as np
8
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
26 import matplotlib
27 import matplotlib.colorbar
---> 28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
30 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/__init__.py in <module>()
1 from __future__ import absolute_import
2
----> 3 from .core import use, context, available, library, reload_library
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in <module>()
147 # Load style library
148 # ==================
--> 149 _base_library = load_base_library()
150
151 library = None
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in load_base_library()
92 """Load style library defined in this package."""
93 library = dict()
---> 94 library.update(read_style_directory(BASE_LIBRARY_PATH))
95 return library
96
/home/guras/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/style/core.py in read_style_directory(style_dir)
125 styles = dict()
126 for path, name in iter_style_files(style_dir):
--> 127 styles[name] = rc_params_from_file(path, use_default_template=False)
128 return styles
129
TypeError: **rc_params_from_file() got an unexpected keyword argument 'use_default_template'**
Any ideas how to fix it?
The use_default_template keyword parameter was added to the rc_params_from_file function in matplotlib version 1.4.0rc1.
Most likely, your version of matplotlib is older than 1.4.0rc1 and needs to be upgraded.
If you have more than one installation of matplotlib installed, you'll need to make sure the directory containing the newer version is listed earlier than the older version in sys.path, or perhaps, simply delete the older version of matplotlib.
Use the Canopy Package Manager to update matplotlib to the latest version.
Related
I'm having trouble importing nglview inside a Juypter Notebook (JNb) cell. The instance of JNb is started via the base (root) Environment inside Anaconda.Navigator GUI. Inside Anaconda.Navigator, I've installed nglview. But the import continues to fail.
Versions:
Jupyter Notebook (inside Anaconda.Navigator) - 6.4.12
Anaconda.Navigator (GUI) - 2.3.2
Python - 3.9
nglview - 3.0.3 (installed but not importing)
ipython 8.5.0
This is the error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In [1], line 5
3 import pandas as pd
4 import matplotlib.pyplot as plt
----> 5 import nglview as nv
7 # the next line is necessary to display plots in Jupyter
8 get_ipython().run_line_magic('matplotlib', 'inline')
File ~\anaconda3\lib\site-packages\nglview\__init__.py:4
1 import warnings
3 # for doc
----> 4 from . import adaptor, datafiles, show, widget
5 from ._version import get_versions
6 from .adaptor import *
File ~\anaconda3\lib\site-packages\nglview\show.py:13
3 from . import datafiles
4 from .adaptor import (ASEStructure, ASETrajectory, BiopythonStructure,
5 FileStructure, HTMDTrajectory, IODataStructure,
6 IOTBXStructure, MDAnalysisTrajectory, MDTrajTrajectory,
(...)
11 RdkitStructure,
12 TextStructure)
---> 13 from .widget import NGLWidget
15 __all__ = [
16 'demo',
17 'show_pdbid',
(...)
40 'show_biopython',
41 ]
44 def show_pdbid(pdbid, **kwargs):
File ~\anaconda3\lib\site-packages\nglview\widget.py:19
15 from traitlets import (Bool, CaselessStrEnum, Dict, Instance, Int, Integer,
16 List, Unicode, observe, validate)
17 import traitlets
---> 19 from . import color, interpolate
20 from .adaptor import Structure, Trajectory
21 from .component import ComponentViewer
File ~\anaconda3\lib\site-packages\nglview\color.py:114
110 else:
111 raise ValueError(f"{obj} must be either list of list or string")
--> 114 ColormakerRegistry = _ColormakerRegistry()
File ~\anaconda3\lib\site-packages\nglview\base.py:10, in _singleton.<locals>.getinstance()
8 def getinstance():
9 if cls not in instances:
---> 10 instances[cls] = cls()
11 return instances[cls]
File ~\anaconda3\lib\site-packages\nglview\color.py:47, in _ColormakerRegistry.__init__(self, *args, **kwargs)
45 try:
46 get_ipython() # only display in notebook
---> 47 self._ipython_display_()
48 except NameError:
49 pass
File ~\anaconda3\lib\site-packages\nglview\color.py:54, in _ColormakerRegistry._ipython_display_(self, **kwargs)
52 if self._ready:
53 return
---> 54 super()._ipython_display_(**kwargs)
AttributeError: 'super' object has no attribute '_ipython_display_'
What is missing? I need to resolve this issue within the GUI of Anaconda.Navigator, as I need nglview as part of an exercise for students who do not have a background in computational sciences. I'm not after a solution that uses anything but the GUI. Asking a group over Zoom to start hacking around with a Mac/Windows/Linux terminal would be a nightmare. Many thanks.
UPDATE
Recent efforts have included:
closing and restarting Anaconda.Navigator GUI
"Quit" the Jupyter server (option found in the browser tab). Restarted the server.
%conda install -c conda-forge nglview at the top of the Notebook. It just informs me that it's already installed.
Closing the tab and all mentions of Anaconda and Jupyter (but not the browser window instance itself).
The fact that I haven't restarted the machine itself is a big grey elephant. Unfortunately, it's running a long Quantum chemistry calculation in the background that can't be continued after boot :-( Sorry. But I don't want to get hung up on restarting a machine - it shouldn't come down to that.
Check whether the version of ipywidget in your current conda version is above 8.0.0. Because Jupyter notebook is not compatible with the new version of ipywidget. Thus try the command below to install the older version of ipywidget, then ǹglview` should be properly imported:
conda install "ipywidgets <8" -c conda-forge
I'm not being able to use the read_file method of geopandas. below is the code and the stack trace
import geopandas as gpd
path_to_data = gpd.datasets.get_path("nybb")
gdf = gpd.read_file(path_to_data)
error trace:
ImportError Traceback (most recent call last)
Input In [5], in <module>
1 path_to_data = gpd.datasets.get_path("nybb")
----> 2 gdf = gpd.read_file(path_to_data)
4 gdf
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:166, in _read_file(filename, bbox, mask, rows, **kwargs)
104 def _read_file(filename, bbox=None, mask=None, rows=None, **kwargs):
105 """
106 Returns a GeoDataFrame from a file or URL.
107
(...)
164 by using the encoding keyword parameter, e.g. ``encoding='utf-8'``.
165 """
--> 166 _check_fiona("'read_file' function")
167 filename = _expand_user(filename)
169 if _is_url(filename):
File ~/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/geopandas/io/file.py:80, in _check_fiona(func)
78 def _check_fiona(func):
79 if fiona is None:
---> 80 raise ImportError(
81 f"the {func} requires the 'fiona' package, but it is not installed or does "
82 f"not import correctly.\nImporting fiona resulted in: {fiona_import_error}"
83 )
ImportError: the 'read_file' function requires the 'fiona' package, but it is not installed or does not import correctly.
Importing fiona resulted in: dlopen(/Users/junaid/Desktop/Udemy_projects/multiple/lib/python3.9/site-packages/fiona/ogrext.cpython-39-darwin.so, 0x0002): Library not loaded: /opt/homebrew/opt/proj#7/lib/libproj.19.dylib
Referenced from: /opt/homebrew/Cellar/gdal/3.4.1_1/lib/libgdal.30.dylib
Reason: tried: '/opt/homebrew/opt/proj#7/lib/libproj.19.dylib' (no such file), '/usr/local/lib/libproj.19.dylib' (no such file), '/usr/lib/libproj.19.dylib' (no such file)
It looks like geopandas is referening an older version of PROJ. I used to have proj 7.2 but now have 8.2.1 installed.
Also I have the following versions of fiona and gdal
fiona 1.8.19
GDAL 3.3.3
any help would be much appreciated
Have you tried to install the Fiona package? Because it requires this package from your error.
I get this long error when i try importing pyplot in ipython. Everything works fine when i try the same in jupyter notebook.
I think I've tried all the suggestions I found about pyplot import errors. I tried reinstalling matplotlib, ipykernel, zmq etc etc., I tried rolling back to old versions. I've tried matching sys.path from notebook and my ipython kernel, but no success.
I'm using python 3.7, windows 10, ConEmu for ipython kernel.
from matplotlib import pyplot
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-02aaac1810fb> in <module>
----> 1 from matplotlib import pyplot
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
2347 dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
2348 # Set up the backend.
-> 2349 switch_backend(rcParams["backend"])
2350
2351 # Just to be safe. Interactive mode can be turned on without
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in switch_backend(newbackend)
219 else "matplotlib.backends.backend_{}".format(newbackend.lower()))
220
--> 221 backend_mod = importlib.import_module(backend_name)
222 Backend = type(
223 "Backend", (matplotlib.backends._Backend,), vars(backend_mod))
C:\ProgramData\Python3\Continuum\anaconda3\lib\importlib\__init__.py in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
128
129
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_tkagg.py in <module>
1 from . import _backend_tk
----> 2 from .backend_agg import FigureCanvasAgg
3 from ._backend_tk import (
4 _BackendTk, FigureCanvasTk, FigureManagerTk, NavigationToolbar2Tk)
5
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in <module>
43
44 if _has_pil:
---> 45 from PIL import Image
46
47 backend_version = 'v2.2'
C:\ProgramData\Python3\Continuum\anaconda3\lib\site-packages\PIL\Image.py in <module>
93 # Also note that Image.core is not a publicly documented interface,
94 # and should be considered private and subject to change.
---> 95 from . import _imaging as core
96
97 if __version__ != getattr(core, "PILLOW_VERSION", None):
ImportError: DLL load failed: The specified module could not be found.
I have tensorflow version 1.0.0 non-GPU version on my macbook pro Yosemite. It is installed in a virtualenv, and I have python 2.7. I have six version 1.4.1. When I do python on the command line and import six, it works fine. But when I enter 'ipython' and import tensorflow, I see this error:
AttributeError Traceback (most recent call last)
<ipython-input-1-cd232424f60d> in <module>()
----> 1 execfile('hw4/net.py')
/Users/lingxiao/Documents/research/dialogue-systems/hw4/net.py in <module>()
8 import time
9 import numpy as np
---> 10 import tensorflow as tf
11
12 import app
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/__init__.py in <module>()
22
23 # pylint: disable=wildcard-import
---> 24 from tensorflow.python import *
25 # pylint: enable=wildcard-import
26
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/__init__.py in <module>()
122 from tensorflow.python.platform import resource_loader
123 from tensorflow.python.platform import sysconfig
--> 124 from tensorflow.python.platform import test
125
126 from tensorflow.python.util.all_util import remove_undocumented
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/test.py in <module>()
67 # pylint: disable=g-bad-import-order
68 from tensorflow.python.client import device_lib as _device_lib
---> 69 from tensorflow.python.framework import test_util as _test_util
70 from tensorflow.python.platform import googletest as _googletest
71 from tensorflow.python.util.all_util import remove_undocumented
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/test_util.py in <module>()
41 from tensorflow.python.framework import random_seed
42 from tensorflow.python.framework import versions
---> 43 from tensorflow.python.platform import googletest
44 from tensorflow.python.platform import tf_logging as logging
45 from tensorflow.python.util import compat
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/googletest.py in <module>()
31
32 from tensorflow.python.platform import app
---> 33 from tensorflow.python.platform import benchmark # pylint: disable=unused-import
34
35 Benchmark = benchmark.TensorFlowBenchmark # pylint: disable=invalid-name
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/benchmark.py in <module>()
115
116
--> 117 class Benchmark(six.with_metaclass(_BenchmarkRegistrar, object)):
118 """Abstract class that provides helper functions for running benchmarks.
119
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six.pyc in with_metaclass(meta, *bases)
564 def with_metaclass(meta, *bases):
565 """Create a base class with a metaclass."""
--> 566 return meta("NewBase", bases, {})
567
568 def add_metaclass(metaclass):
/Users/lingxiao/tensorflow/lib/python2.7/site-packages/tensorflow/python/platform/benchmark.py in __new__(mcs, clsname, base, attrs)
110 newclass = super(mcs, _BenchmarkRegistrar).__new__(
111 mcs, clsname, base, attrs)
--> 112 if not newclass.is_abstract():
113 GLOBAL_BENCHMARK_REGISTRY.add(newclass)
114 return newclass
AttributeError: type object 'NewBase' has no attribute 'is_abstract'
I tried upgrading six and I am still seeing version 1.4.1. Is six the problem here? if not what is?
It seems that there's a number of things tangled. I'm using Anaconda2 with six==1.10.0, tensorflow==1.0.0 and Python 2.7.12. A quick experiment would be to install Anaconda2 (i.e. with python2.7) then pip install TF and other dependencies and try it out.
The Anaconda installation is self-contained, so that you won't be affected by other system-wide issues. I just did it by running /Users/myusername/anaconda2/bin/ipython
My guess is that you need to install iPython from within the virtual environment. if you haven't done that, ipython will use the vanilla interpreter even though you are in a virtual environment.
After I installed the package Iris with conda install -c scitools iris,
Whether using Ipython console or Jupyter notebook, the iris was always failed to import. The error subroutine shows like:
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-1-005053b25f37> in <module>()
----> 1 import iris
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/__init__.pyc in <module>()
110 import iris.cube
111 import iris._constraints
--> 112 import iris.fileformats
113 import iris.io
114
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/__init__.py in <module>()
23 from six.moves import (filter, input, map, range, zip) # noqa
24
---> 25 from iris.io.format_picker import (FileExtension, FormatAgent,
26 FormatSpecification, MagicNumber,
27 UriProtocol, LeadingLine)
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/io/__init__.py in <module>()
31
32 import iris.fileformats
---> 33 import iris.fileformats.dot
34 import iris.cube
35 import iris.exceptions
/Users/TEST/anaconda/lib/python2.7/site-packages/iris/fileformats/dot.py in <module>()
41 # Check PATH
42 subprocess.check_output([_DOT_EXECUTABLE_PATH, '-V'],
---> 43 stderr=subprocess.STDOUT)
44 except OSError:
45 _DOT_EXECUTABLE_PATH = None
/Users/TEST/anaconda/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
571 if cmd is None:
572 cmd = popenargs[0]
--> 573 raise CalledProcessError(retcode, cmd, output=output)
574 return output
575
CalledProcessError: Command '['dot', '-V']' returned non-zero exit status -5
I raised a similar issue on the iris GitHub tracker (https://github.com/SciTools/iris/issues/1899). Essentially, as much as I believe it was intended to be optional, the way it has been implemented I think Iris actually requires a dot installation. With conda, that should look like:
conda install graphviz
HTH
In my particular case, this error was resolved by installing GraphViz.
I believe the root case of this issue is that the graphiz python bindings cannot find the command line utilities required to render the output into some form, e.g. .pdf, .svg or .png.