使用ggplot获取不安全的pickle字符串

时间:2016-02-14 21:51:13

标签: python matplotlib python-ggplot

我正在尝试使用ggplot在iPython Notebook中运行Python,但在运行from ggplot import *时会出现以下错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-22-2199c088d178> in <module>()
      2 import numpy as np
      3 import dateutil
----> 4 from ggplot import *

~/ipython-venv/lib/python2.7/site-packages/ggplot/__init__.py in <module>()
     19 __version__ = '0.6.8'
     20 
---> 21 from .qplot import qplot
     22 from .ggplot import ggplot
     23 from .components import aes

~/ipython-venv/lib/python2.7/site-packages/ggplot/qplot.py in <module>()
      3 
      4 import ggplot
----> 5 from .components import aes
      6 from .geoms import geom_point, geom_bar, geom_boxplot, geom_histogram, geom_line
      7 from .geoms.chart_components import xlab as xlabel

~/ipython-venv/lib/python2.7/site-packages/ggplot/components/__init__.py in <module>()
      2                         unicode_literals)
      3 from .aes import aes
----> 4 from . import colors, shapes, size, linetypes, alphas
      5 
      6 

~/ipython-venv/lib/python2.7/site-packages/ggplot/components/colors.py in <module>()
      4 import numpy as np
      5 from matplotlib.colors import rgb2hex
----> 6 from ..utils.color import ColorHCL
      7 from .legend import get_labels
      8 from copy import deepcopy

~/ipython-venv/lib/python2.7/site-packages/ggplot/utils/__init__.py in <module>()
      2                         unicode_literals)
      3 
----> 4 from .ggutils import ggsave, add_ggplotrc_params
      5 from .date_breaks import date_breaks
      6 from .date_format import date_format

~/ipython-venv/lib/python2.7/site-packages/ggplot/utils/ggutils.py in <module>()
      4                         unicode_literals)
      5 
----> 6 import matplotlib.pyplot as plt
      7 import json
      8 import os

~/ipython-venv/lib/python2.7/site-packages/matplotlib/pyplot.py in <module>()
     27 from cycler import cycler
     28 import matplotlib
---> 29 import matplotlib.colorbar
     30 from matplotlib import style
     31 from matplotlib import _pylab_helpers, interactive

~/ipython-venv/lib/python2.7/site-packages/matplotlib/colorbar.py in <module>()
     32 import matplotlib.artist as martist
     33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
     35 import matplotlib.colors as colors
     36 import matplotlib.contour as contour

~/ipython-venv/lib/python2.7/site-packages/matplotlib/collections.py in <module>()
     25 import matplotlib.artist as artist
     26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
     28 import matplotlib.path as mpath
     29 from matplotlib import _path

~/ipython-venv/lib/python2.7/site-packages/matplotlib/backend_bases.py in <module>()
     60 
     61 import matplotlib.tight_bbox as tight_bbox
---> 62 import matplotlib.textpath as textpath
     63 from matplotlib.path import Path
     64 from matplotlib.cbook import mplDeprecation, warn_deprecated

~/ipython-venv/lib/python2.7/site-packages/matplotlib/textpath.py in <module>()
     13 from matplotlib.path import Path
     14 from matplotlib import rcParams
---> 15 import matplotlib.font_manager as font_manager
     16 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
     17 from matplotlib.ft2font import LOAD_TARGET_LIGHT

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in <module>()
   1419                 verbose.report("Using fontManager instance from %s" % _fmcache)
   1420         except:
-> 1421             _rebuild()
   1422     else:
   1423         _rebuild()

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in _rebuild()
   1404     def _rebuild():
   1405         global fontManager
-> 1406         fontManager = FontManager()
   1407         if _fmcache:
   1408             pickle_dump(fontManager, _fmcache)

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in __init__(self, size, weight)
   1042         #  Load TrueType fonts and create font dictionary.
   1043 
-> 1044         self.ttffiles = findSystemFonts(paths) + findSystemFonts()
   1045         self.defaultFamily = {
   1046             'ttf': 'Bitstream Vera Sans',

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in findSystemFonts(fontpaths, fontext)
    322                     fontfiles[f] = 1
    323 
--> 324             for f in get_fontconfig_fonts(fontext):
    325                 fontfiles[f] = 1
    326 

~/ipython-venv/lib/python2.7/site-packages/matplotlib/font_manager.py in get_fontconfig_fonts(fontext)
    274         pipe = subprocess.Popen(['fc-list', '--format=%{file}\\n'],
    275                                 stdout=subprocess.PIPE,
--> 276                                 stderr=subprocess.PIPE)
    277         output = pipe.communicate()[0]
    278     except (OSError, IOError):

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    708                                 p2cread, p2cwrite,
    709                                 c2pread, c2pwrite,
--> 710                                 errread, errwrite)
    711         except Exception:
    712             # Preserve original exception in case os.close raises.

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
   1332                     if e.errno != errno.ECHILD:
   1333                         raise
-> 1334                 child_exception = pickle.loads(data)
   1335                 raise child_exception
   1336 

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in loads(str)
   1386 def loads(str):
   1387     file = StringIO(str)
-> 1388     return Unpickler(file).load()
   1389 
   1390 # Doctest

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load(self)
    862             while 1:
    863                 key = read(1)
--> 864                 dispatch[key](self)
    865         except _Stop, stopinst:
    866             return stopinst.value

/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.pyc in load_string(self)
    970             if rep.startswith(q):
    971                 if len(rep) < 2 or not rep.endswith(q):
--> 972                     raise ValueError, "insecure string pickle"
    973                 rep = rep[len(q):-len(q)]
    974                 break

ValueError: insecure string pickle

环境运行在OS-X El Capitan上,Python 2.x通过HomeBrew安装,并安装了以下库:

  

(ipython-venv)➜~piplist appnope(0.1.0)backports-abc(0.4)   backports.ssl-match-hostname(3.5.0.1)beautifulsoup4(4.4.1)   brewer2mpl(1.4.1)certifi(2015.11.20.1)cycler(0.9.0)装饰器   (4.0.6)functools32(3.2.3.post2)ggplot(0.6.8)gnureadline(6.3.3)   ipykernel(4.2.2)ipython(4.0.3)ipython-genutils(0.1.0)Jinja2   (2.8)jsonschema(2.5.1)jupyter-client(4.1.1)jupyter-core(4.0.6)   MarkupSafe(0.23)matplotlib(1.5.1)机械化(0.2.5)雾化(0.7.1)   nbconvert(4.1.0)nbformat(4.0.1)notebook(4.1.0)numpy(1.10.4)   pandas(0.17.1)path.py(8.1.2)patsy(0.4.1)pexpect(4.0.1)   pickleshare(0.6)pip(8.0.2)ptyprocess(0.5)Pygments(2.1)   pyparsing(2.1.0)python-dateutil(2.4.2)pytz(2015.7)pyzmq(15.2.0)   scipy(0.17.0)selenium(2.50.0)setuptools(15.0)simplegeneric   (0.8.1)singledispatch(3.4.0.3)六(1.10.0)statsmodels(0.6.1)   termcolor(1.1.0)terminado(0.6)龙卷风(4.3)traitlets(4.1.0)

1 个答案:

答案 0 :(得分:2)

这里已经讨论过:github.com/matplotlib/matplotlib/pull/5640

这可能是权限问题 - matplotlib不应每次都构建该缓存

建议删除~/.cache/matplotlib的内容,然后重试。