ImportError:没有名为'matplotlib.externals'的模块

And*_*ndy 7 python ubuntu matplotlib seaborn

当我在Ubuntu 16.04上使用python3中的seaborn.heatmap运行file1.py时,

我收到错误消息:

Traceback (most recent call last):
  File "file1.py", line 19, in <module>
    import seaborn as sns
ImportError: No module named 'seaborn'
Run Code Online (Sandbox Code Playgroud)

然后我$ sudo apt install python3-seaborn在终端运行命令:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libdsdp-5.8gf libglade2-0 libglpk36 python-cvxopt python-cycler
  python-decorator python-glade2 python-imaging python-jdcal python-joblib
  python-numexpr python-openpyxl python-pandas python-pandas-lib python-patsy
  python-py python-pytest python-scipy python-statsmodels
  python-statsmodels-lib python-tables python-tables-lib
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  python3-matplotlib
Suggested packages:
  ffmpeg ipython3 python-matplotlib-doc python3-cairocffi python3-gobject
  python3-nose python3-pyqt4 python3-sip python3-tornado ttf-staypuft
The following NEW packages will be installed:
  python3-matplotlib python3-seaborn
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3,999 kB of archives.
After this operation, 13.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Selecting previously unselected package python3-matplotlib.
(Reading database ... 378283 files and directories currently installed.)
Preparing to unpack .../python3-matplotlib_1.5.1-1ubuntu1_amd64.deb ...
Unpacking python3-matplotlib (1.5.1-1ubuntu1) ...
Selecting previously unselected package python3-seaborn.
Preparing to unpack .../python3-seaborn_0.6.0-1_all.deb ...
Unpacking python3-seaborn (0.6.0-1) ...
Setting up python3-matplotlib (1.5.1-1ubuntu1) ...
Setting up python3-seaborn (0.6.0-1) ...
Run Code Online (Sandbox Code Playgroud)

现在file1.py可以成功运行,而我在python3中使用Axes3D运行file2.py,我收到错误消息:

Traceback (most recent call last):
  File "file2.py", line 29, in <module>
    from mpl_toolkits.mplot3d import Axes3D
  File "/usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/__init__.py", line 4, in <module>
    from matplotlib.externals import six
ImportError: No module named 'matplotlib.externals'
Run Code Online (Sandbox Code Playgroud)

只有我运行$ sudo apt remove python3-matplotlib才能运行file2.py:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fonts-lyx libjs-jquery-ui python-matplotlib-data python-tables-data python3-cycler
  python3-dateutil python3-decorator python3-numexpr python3-pandas python3-pandas-lib python3-patsy
  python3-scipy python3-tables python3-tables-lib python3-tz
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python3-matplotlib python3-seaborn
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 13.8 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 375396 files and directories currently installed.)
Removing python3-seaborn (0.6.0-1) ...
Removing python3-matplotlib (1.5.1-1ubuntu1) ...
Run Code Online (Sandbox Code Playgroud)

但是,python3-seaborn也同时被删除.我怎么解决这个问题?提前致谢!

Vla*_*hin 6

sudo apt-get remove python3-matplotlib

UPD:然后使用常规pip方式安装它: sudo pip3 install matplotlib

此外,@ Andy已经注意到该脚本不仅会删除,matplotlib而且还会删除seaborn.所以,您可能还需要使用它来安装它pip.


我试图做@ Bodhi94建议的但是没有成功.然后我试图python3-matplotlib从Ubuntu中删除它并解决了.

是否可能出现任何冲突?请允许我,如果有的话.


Bod*_*i94 5

尝试使用以下命令重新安装matplotlib。

 sudo pip install matplotlib --upgrade --ignore-installed six
Run Code Online (Sandbox Code Playgroud)