Python 3.5 Jupyter笔记本ggplot“名称错误”
问题描述:
当在运行Python 3.5.2的Jupyter笔记本中使用yHat的Python ggplot库(请参阅下面的完整错误)时,我得到NameError: name 'unicode' is not defined
。用下面的import语句:Python 3.5 Jupyter笔记本ggplot“名称错误”
%matplotlib inline
from ggplot import *
图形渲染依旧,但我想,以消除误差,或隐藏如果不引起大的冲突。
完整的错误如下。非常感谢提前:) :)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
//anaconda/lib/python3.5/site-packages/IPython/core/formatters.py in __call__(self, obj)
697 type_pprinters=self.type_printers,
698 deferred_pprinters=self.deferred_printers)
--> 699 printer.pretty(obj)
700 printer.flush()
701 return stream.getvalue()
//anaconda/lib/python3.5/site-packages/IPython/lib/pretty.py in pretty(self, obj)
381 if callable(meth):
382 return meth(obj, self, cycle)
--> 383 return _default_pprint(obj, self, cycle)
384 finally:
385 self.end_group()
//anaconda/lib/python3.5/site-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
501 if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
502 # A user-provided repr. Find newlines and replace them with p.break_()
--> 503 _repr_pprint(obj, p, cycle)
504 return
505 p.begin_group(1, '<')
//anaconda/lib/python3.5/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
692 """A pprint that just redirects to the normal repr function."""
693 # Find newlines and replace them with p.break_()
--> 694 output = repr(obj)
695 for idx,output_line in enumerate(output.splitlines()):
696 if idx:
//anaconda/lib/python3.5/site-packages/ggplot/ggplot.py in __repr__(self)
113 Evaluates patsy expressions within the aesthetics. For example, 'x + 1'
114 , 'factor(x)', or 'pd.cut(price, bins=10)')
--> 115 """
116 for key, item in self._aes.items():
117 if item not in self.data:
//anaconda/lib/python3.5/site-packages/ggplot/ggplot.py in make(self)
//anaconda/lib/python3.5/site-packages/ggplot/ggplot.py in apply_axis_labels(self)
269 i, j = self.subplots.shape
270 i, j = int((i - 1)/2), int(j - 1)
--> 271 ax = self.subplots[i][j]
272 make_legend(ax, legend)
273 elif self.facets.rowvar:
NameError: name 'unicode' is not defined
答
如果您安装了anaconda,请尝试安装code-forge版本。我能够通过切换到该版本为Python 3.5
conda install -c conda-forge ggplot
希望帮助
+0
谢谢,我会试试这个。我最终为Jupyter添加了Python 2.7内核,然后在2.7而不是3.5.2上运行ggplot – typeofgraphic
它可能不是PY3保存修复此相同的问题:https://github.com/yhat/ggplot/blob /b6492aaff6aae5301fa838a24e4416c092e03f24/ggplot/ggplot.py#L271->测试也不是py3保存,所以我想它只是py2 ... –