Updating matplotlib in virtualenv with pip
Asked Answered
P

3

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
Procurance answered 1/12, 2017 at 14:3 Comment(0)
D
23

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

pip install matplotlib==2.1.0

or

pip install --upgrade matplotlib

Demulsify answered 1/12, 2017 at 14:27 Comment(5)
do i use the pip in myenv/bin/pip or the usual pip ?Procurance
i did that and it still gives matplotlib version 1.3.1 in virtual pythonProcurance
do I need to add anything to my .bashrc to make the changes ?Procurance
#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 .bashrcDemulsify
I added the output of pip freezeProcurance
S
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

Segarra answered 31/1, 2019 at 5:40 Comment(0)
H
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.
Hebdomad answered 24/6, 2024 at 19:54 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.