问题
I've setted up a virtual enviroment for playing around with machine learning using pyenv
. When i run import matplotlib.pyplot as plt
this i what i get:
ImportError Traceback (most recent call last)
<ipython-input-1-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
/usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/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
/usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/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
/usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/site-packages/matplotlib/artist.py in <module>()
12 from matplotlib.cbook import mplDeprecation
13 from matplotlib import docstring, rcParams
---> 14 from .transforms import (Bbox, IdentityTransform, TransformedBbox,
15 TransformedPath, Transform)
16 from .path import Path
/usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/site-packages/matplotlib/transforms.py in <module>()
37 import numpy as np
38 from numpy import ma
---> 39 from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
40 update_path_extents)
41 from numpy.linalg import inv
ImportError: dlopen(/usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/site-packages/matplotlib/_path.so, 2): Symbol not found: _PyUnicodeUCS2_AsASCIIString
Referenced from: /usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/site-packages/matplotlib/_path.so
Expected in: flat namespace
in /usr/local/var/pyenv/versions/2.7.11/envs/machine_learning/lib/python2.7/site-packages/matplotlib/_path.so
I'm on OS X Yosemite
and this is my library of packages which i've installed via pip
:
appnope==0.1.0
backports.shutil-get-terminal-size==1.0.0
cffi==1.6.0
cryptography==1.3.2
cycler==0.10.0
decorator==4.0.9
enum34==1.1.6
gnureadline==6.3.3
idna==2.1
inflection==0.3.1
ipaddress==1.0.16
ipython==4.2.0
ipython-genutils==0.1.0
matplotlib==1.5.1
more-itertools==2.2
mpmath==0.19
ndg-httpsclient==0.4.0
nose==1.3.7
numpy==1.11.0
pandas==0.18.1
pathlib2==2.1.0
pexpect==4.0.1
pickleshare==0.7.2
ptyprocess==0.5.1
pyasn1==0.1.9
pycparser==2.14
pyOpenSSL==16.0.0
pyparsing==2.1.4
python-dateutil==2.5.3
pytz==2016.4
Quandl==3.0.0
readline==6.2.4.1
requests==2.10.0
scikit-learn==0.17.1
scipy==0.17.1
simplegeneric==0.8.1
six==1.10.0
sympy==1.0
traitlets==4.2.1
There is a solution for fixing this problem?
回答1:
I've figured out the solution! It seems that the python version (2.7.11
) that i was using in my virtual environment was configured in order to use unicode=ucs4
, so simply uninstalling virtualenv/python version and running
PYTHON_CONFIGURE_OPTS="--enable-unicode=ucs2" pyenv install 2.7.11
fixed the problem!
回答2:
For those who are using python3 or not in a special environment, I found that the conda folks have been working on this issue. What worked for me was from https://github.com/conda-forge/matplotlib-feedstock/issues/32
I did
conda install libgcc
And now my import does not throw an error.
来源:https://stackoverflow.com/questions/37496685/issue-when-importing-matplotlib