Matplotlib doesn't display graph in virtualenv

后端 未结 5 884
予麋鹿
予麋鹿 2021-02-05 11:53

I have pip installed matplotlib in my virtualenv and I am trying to plot a simple graph. I use Eclipse and PyDev. When I run the script from Eclipse it doesn\'t display any grap

相关标签:
5条回答
  • 2021-02-05 12:29

    First off, you might want to check out:

    http://matplotlib.org/faq/installing_faq.html#matplotlib-compiled-fine-but-nothing-shows-up-when-i-use-it

    To see what's going wrong, check out the matplotlib using git instead of either pip or easy_install. We're going to do a more manual install:

    git clone git@github.com:matplotlib/matplotlib.git
    cd matplotlib
    python setup.py
    

    This will print out the configuration of what pip or easy_install would have done. Look through the "OPTIONAL BACKEND DEPENDENCIES" and make sure that some of the ones that produce windows are enabled (Tkinter, Gtk+, Mac OS X native, Qt, Cairo, etc.). If you see that none of these are available, then you need to install some of these libraries for your operating system before you continue installing matplotlib.

    After installing say, Tk (on ubuntu: sudo apt-get install tcl-dev tk-dev), then when you re-run

    python setup.py
    

    you will see that the Tk backend is enabled. Proceeding with

    python setup.py build && python setup.py install
    

    should get you up and running... but at that point you might even just delete the whole git clone directory and go back to installing with pip.

    0 讨论(0)
  • 2021-02-05 12:37

    I had the same issue, and installing matplotlib using easy_install instead of pip did not solve it. In the end, I found out that the problem was simply that matplotlib could not find any backend for plotting.

    I solved it by doing the following (I am using Debian wheezy):

    pip uninstall matplotlib
    sudo apt-get install tcl-dev tk-dev
    pip install matplotlib
    
    0 讨论(0)
  • 2021-02-05 12:41

    Your code works inside my virtualenv on OSX 10.7 with Python 2.7:

    enter image description here

    What version of Python are you using inside your virtualenv? My guess is that either you have not installed a matplotlib dependency or your installation of an installed dependency was not properly performed. On Python 2.7 here is what I did to install matplotlib. Can you try these steps in a new virtualenv and see if it works for you?

    pip install numpy
    pip install scipy
    easy_install matplotlib
    
    0 讨论(0)
  • 2021-02-05 12:48

    If you have a version of matplotlib installed on your system version of python, then you can link to the system version of matplotlib. On my machine I did the following:

    cd $VIRTUAL_ENV/lib/python2.7/site-packages
    ln -s /usr/lib/pymodules/python2.7/matplotlib .
    ln -s /usr/lib/pymodules/python2.7/matplotlib-1.1.1rc .
    

    This avoids many of the problems with getting matplotlib to work in the virtualenv but limits you to using the system version of matplotlib (which on this machine is not too bad).

    This method also allows you to use the --no-site-packages, but still have matplotlib work for you.

    0 讨论(0)
  • 2021-02-05 12:51

    I am using Ubuntu 12.04 and Python 2.7.3 on my computer and when I use the matplotlib 1.2.0 in my virtualenv, the show() did not work until I upgrade it to the 1.2.1... All the bugs I had previous went away...

    By doing this you will install all the dependencies of the matplotlib:

    sudo apt-get build-dep python-matplotlib
    

    To get the latest version of the matplotlib you can use:

    pip install matplotlib
    

    or upgrade it:

    pip install matplotlib --upgrade
    
    0 讨论(0)
提交回复
热议问题