简体   繁体   English

python 3.6.2 中的 %matplotlib 内联错误

[英]%matplotlib inline error in python 3.6.2

How to run a code on my computer?如何在我的电脑上运行代码?


I am trying to run my code on my computer, but somehow get an error:我试图在我的计算机上运行我的代码,但不知何故出现错误:

File "catcode.py", line 9文件“catcode.py”,第 9 行

%matplotlib inline

^

SyntaxError: invalid syntax

I am using macOS Sierra 10.12.6 , MacBook Pro (Retina, 13-inch, Early 2015), 2.9 GHz Intel Core i5, 8 GB 1867 MHz DDR3, Intel Iris Graphics 6100 1536 MB.我使用的是macOS Sierra 10.12.6 、MacBook Pro(Retina,13 英寸,2015 年初)、2.9 GHz Intel Core macOS Sierra 10.12.6 GB 1867 MHz DDR3、Intel Iris Graphics 6100 1536 MB。

I am also using python 3 through terminal:我也通过终端使用python 3

Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)

[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] 在达尔文

This is the list of packages I have:这是我拥有的软件包列表:

['appnope==0.1.0', 'cycler==0.10.0', 'decorator==4.1.2', 'h5py==2.7.1', 'ipython-genutils==0.2.0', 'ipython==6.2.1', 'jedi==0.11.0', 'matplotlib==2.1.0', 'numpy==1.13.3', 'parso==0.1.0', 'pexpect==4.2.1', 'pickleshare==0.7.4', 'pip==9.0.1', 'prompt-toolkit==1.0.15', 'ptyprocess==0.5.2', 'pygments==2.2.0', 'pyparsing==2.2.0', 'python-dateutil==2.6.1', 'pytz==2017.2', 'scikit-learn==0.19.0', 'scipy==0.19.1', 'setuptools==28.8.0', 'simplegeneric==0.8.1', 'six==1.11.0', 'traitlets==4.3.2', 'wcwidth==0.1.7'] ['appnope==0.1.0', 'cycler==0.10.0', 'decorator==4.1.2', 'h5py==2.7.1', 'ipython-genutils==0.2.0', 'ipython ==6.2.1'、'绝地==0.11.0'、'matplotlib==2.1.0'、'numpy==1.13.3'、'parso==0.1.0'、'pexpect==4.2.1 ', 'pickleshare==0.7.4', 'pip==9.0.1', 'prompt-toolkit==1.0.15', 'ptyprocess==0.5.2', 'pygments==2.2.0', ' pyparsing==2.2.0'、'python-dateutil==2.6.1'、'pytz==2017.2'、'scikit-learn==0.19.0'、'scipy==0.19.1'、'setuptools== 28.8.0', 'simplegeneric==0.8.1', 'six==1.11.0', 'traitlets==4.3.2', 'wcwidth==0.1.7']

%matplotlib inline is a "magic function" that decorates a cell in a Jupyter notebook. %matplotlib inline是一个“神奇的函数”,用于装饰 Jupyter 笔记本中的单元格。

You can't use it outside of jupyter notebook , and ipython console您不能在jupyter notebookipython console之外使用它

The best solution for you, is probably to comment out the line;对您来说最好的解决方案可能是注释掉该行; other than that, you can install jupyter and ipython.除此之外,您可以安装 jupyter 和 ipython。

'exec(%matplotlib inline)' should work fine. 'exec(%matplotlib inline)'应该可以正常工作。 I have tested it on my system and it works fine with python3.6我已经在我的系统上测试过它,它在 python3.6 上运行良好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM