我在我的 python 脚本中遇到了这个错误:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from utils import progress_bar_downloader
import os
#Hosting files on my dropbox since downloading from google code is painful
#Original project hosting is here: https://code.google.com/p/hmm-speech-recognition/downloads/list
#Audio is included in the zip file
link = 'https://dl.dropboxusercontent.com/u/15378192/audio.tar.gz'
dlname = 'audio.tar.gz'
if not os.path.exists('./%s' % dlname):
progress_bar_downloader(link, dlname)
os.system('tar xzf %s' % dlname)
else:
print('%s already downloaded!' % dlname)
我想使用 matplotlib 但它给出了语法错误, 我试过 sudo apt-get install python-matplotlib
最佳答案
如果您不使用 Jupyter IPython notebook,只需注释掉(或删除)该行,一切都会正常工作,如果您从控制台运行 python 脚本,则会打开一个单独的绘图窗口。
但是,如果您使用的是 Jupyter IPython 笔记本,笔记本中的第一个 Python 代码单元应该有“%matplotlib inline”行,以便您能够查看任何绘图。
关于 python 语法错误: invalid syntax %matplotlib inline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39449549/