16

I am trying to update my matplotlib in virtualenv and now it seems everything crashed :(
what I did till now is basically,

source ~/myenv/bin/activate
pip install -U matplotlib

I had previously matplotlib 1.3 now if I activate py virtual environment and check the matplotlib version it shows 2.1

but I cannot import Axes3D from matplotlib.

>>> import importlib
>>> importlib.import_module('mpl_toolkits.mplot3d').__path__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/nld/python-2.7.6-freya/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/usr/vir_python/lib/python2.7/site-packages/mpl_toolkits/mplot3d/__init__.py", line 6, in <module>
    from .axes3d import Axes3D
  File "/home/usr/vir_python/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 32, in <module>
    from matplotlib.cbook import _backports
ImportError: cannot import name _backports

I working on linux platform and using Python 2.7.

Further problem, I saw,

If I just open virtual python, without activating the virtualenv, I get matplotlib 2.1

$:~> myenv/bin/python 
Python 2.7.6 (default, Apr 15 2014, 11:17:36) 
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'2.1.0'

but if I activate the virtual environment and then open the virtual python with I get matplotlib 1.3.1 or old matplotlib.

$:~> source myenv/bin/activate
(vir_python)$:~> myenv/bin/python
Python 2.7.6 (default, Apr 15 2014, 11:17:36) 
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'1.3.1'

I did the following as per Karthik's suggestion :

First activated the virtual python

(vir_python) $: pip install matplotlib==2.1.0
(vir_python) $: pip freeze
backports.functools-lru-cache==1.4
backports.ssl-match-hostname==3.4.0.2
cycler==0.10.0
imageio==2.1.2
Jinja2==2.7.2
MarkupSafe==0.19
matplotlib==1.3.1
mpi4py==2.0.0
nose==1.3.1
numpy==1.12.0
olefile==0.44
pandas==0.19.2
Pillow==4.0.0
pyparsing==2.0.1
python-dateutil==2.6.0
pytz==2016.10
scipy==0.19.0
six==1.10.0
subprocess32==3.2.7
svg.path==1.1
tornado==3.2
virtualenv==1.11.4

3 Answers 3

25

Your virtualenv has a local matplotlib installed. After sourcing activate, upgrade matplotlib using

pip install matplotlib==2.1.0

or

pip install --upgrade matplotlib

Sign up to request clarification or add additional context in comments.

5 Comments

do i use the pip in myenv/bin/pip or the usual pip ?
i did that and it still gives matplotlib version 1.3.1 in virtual python
do I need to add anything to my .bashrc to make the changes ?
#1. You have to use pip in your virtualenv #2. What is the output of pip freeze command ? #3. No you don't need anything in .bashrc
I added the output of pip freeze
12
plt.__version__
>> 3.0.0

this is current version of matplotlib in my system. In the terminal, give the following comments:

$source activate envname
$pip install --upgrade matplotlib

In python prompt,

import matplotlib as plt
plt.__version__
>> 3.0.2

updates the existing version

Comments

0

I also faced the same issue while upgrading the matplotlib version because of unable to use bar_label() attribute, tried a lot of problems but finally i had to create a new environment. Following are the steps that i followed:

  1. Create a new environment
  2. conda install matplotlib it will automatically install the recent updated version of matplotlib.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.