Anaconda: Unable to import pylab

前端 未结 2 1989
栀梦
栀梦 2021-01-05 01:34

I am unable to import pylab using the latest version of Anaconda (Linux 64 bit). Other packages seem to work fine. (Note: I don\'t have sudo access

相关标签:
2条回答
  • 2021-01-05 02:02

    Following worked for me

    import matplotlib as mpl
    mpl.use('Agg')
    import matplotlib.pylab as pl
    
    0 讨论(0)
  • 2021-01-05 02:21

    Just had this problem and it was related to which qt backend matplotlib was trying to use, try:

    import PyQt4
    

    If you don't have PyQt4 you probably have PySide

    import PySide
    

    If this is the case you need to set the matplotlib.rcParams['backend.qt4'] == 'PySide' not 'PyQt4'. You can also do this in your matplotlibrc file (~/.matplotlib/matplotlibrc)

    # find and change line:
    backend.qt4 : PySide
    

    Note: if you don't have the matplotlibrc file you can copy it from the matplotlib source directory

    import os
    import matplotlib
    mpl_dir = os.path.dirname(matplotlib.__file__)
    os.system("cp {}/mpl-data/matplotlibrc ~/.matplotlib/".format(mpl_dir))
    
    0 讨论(0)
提交回复
热议问题