Anaconda: Unable to import pylab

前端 未结 2 1988
栀梦
栀梦 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: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))
    

提交回复
热议问题