Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'matplotlib.externals'

When I run file1.py using seaborn.heatmap in python3 on Ubuntu 16.04,

I get the error message:

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

Then I run the command $ sudo apt install python3-seaborn in terminal:

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) ...

Now file1.py can be run successfully, while I run file2.py using Axes3D in python3, I get the error message:

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'

Only I run $ sudo apt remove python3-matplotlib can file2.py be run:

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) ...

However, python3-seaborn is also removed at the same time. How can I solve this problem? Thanks in advance!

like image 965
Andy Avatar asked Jul 14 '17 12:07

Andy


3 Answers

sudo apt-get remove python3-matplotlib

UPD: and then install it using conventional pip-way style: sudo pip3 install matplotlib

Also, @Andy has noticed that the script removes not only matplotlib but also seaborn. So, you probably will need to install it using pip as well.


I tried to do what @Bodhi94 suggested but it was not successful. Then I tried to remove python3-matplotlib from Ubuntu and it worked out.

Are there any conflicts may arise? Please, let me if any.

like image 52
Vladimir Iashin Avatar answered Oct 05 '22 07:10

Vladimir Iashin


Try to reinstall matplotlib using following command.

 sudo pip install matplotlib --upgrade --ignore-installed six
like image 34
Vibhutha Kumarage Avatar answered Oct 05 '22 07:10

Vibhutha Kumarage


I replaced in all the Python Files concerned as follow : As soon as I got the message ImportError: No module named 'matplotlib.externals'

I did: -sudo nano /usr/lib/python3/dist-packages/mpl_toolkits/mplot3d/init.py - and I remplace : "from matplotlib.externals import six" by "import six"

Untill there is error left.

Worked perfect since then

like image 38
SimonR Avatar answered Oct 05 '22 09:10

SimonR