Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102213 > unrolled thread
| Started by | Mike S <mscir@yahoo.com> |
|---|---|
| First post | 2016-01-28 23:04 -0800 |
| Last post | 2016-01-29 00:10 -0800 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.python
>>> %matplotlib inline results in SyntaxError: invalid syntax Mike S <mscir@yahoo.com> - 2016-01-28 23:04 -0800
Re: >>> %matplotlib inline results in SyntaxError: invalid syntax Chris Angelico <rosuav@gmail.com> - 2016-01-29 18:32 +1100
Re: >>> %matplotlib inline results in SyntaxError: invalid syntax Steven D'Aprano <steve@pearwood.info> - 2016-01-29 18:57 +1100
Re: >>> %matplotlib inline results in SyntaxError: invalid syntax Mike S <mscir@yahoo.com> - 2016-01-29 00:10 -0800
| From | Mike S <mscir@yahoo.com> |
|---|---|
| Date | 2016-01-28 23:04 -0800 |
| Subject | >>> %matplotlib inline results in SyntaxError: invalid syntax |
| Message-ID | <n8f2ol$fis$1@dont-email.me> |
I have installed Python 3.4.4 on XPSP3 and am trying to work my way through this tutorial. A Complete Tutorial on Ridge and Lasso Regression in Python http://www.analyticsvidhya.com/blog/2016/01/complete-tutorial-ridge-lasso-regression-python/ In Step 2 "Why Penalize the Magnitude of Coefficients?" we are shown this code: #Importing libraries. The same will be used throughout the article. import numpy as np import pandas as pd import random import matplotlib.pyplot as plt %matplotlib inline I get an error on the last line. I am running this code in Idle Python 3.4.4 Shell... Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import numpy as np >>> import pandas as pd >>> import random >>> import matplotlib.pyplot as plt >>> %matplotlib inline SyntaxError: invalid syntax What am I doing wrong? Suggested reading? TIA, Mike
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-29 18:32 +1100 |
| Message-ID | <mailman.78.1454052780.2338.python-list@python.org> |
| In reply to | #102213 |
On Fri, Jan 29, 2016 at 6:04 PM, Mike S via Python-list <python-list@python.org> wrote: > > I get an error on the last line. I am running this code in Idle Python 3.4.4 > Shell... > > Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 bit > (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. >>>> import numpy as np >>>> import pandas as pd >>>> import random >>>> import matplotlib.pyplot as plt >>>> %matplotlib inline > SyntaxError: invalid syntax > > What am I doing wrong? Suggested reading? That's a magic command for ipython - it's not actual Python syntax. You can either install ipython and do the exercises there, or continue with Idle and accept that things will be slightly different. Skim through a few more of the examples; do you see more lines starting with percent signs? If not, you can probably get away with using any interactive Python interpreter (including Idle as you're using above). Alternatively, take the certain route and install ipython - then everything should work. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve@pearwood.info> |
|---|---|
| Date | 2016-01-29 18:57 +1100 |
| Message-ID | <56ab1b6e$0$1602$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #102213 |
On Fri, 29 Jan 2016 06:04 pm, Mike S wrote: > %matplotlib inline > > I get an error on the last line. I am running this code in Idle Python > 3.4.4 Shell... > > Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 > bit (Intel)] on win32 > Type "copyright", "credits" or "license()" for more information. > >>> import numpy as np > >>> import pandas as pd > >>> import random > >>> import matplotlib.pyplot as plt > >>> %matplotlib inline > SyntaxError: invalid syntax > > What am I doing wrong? Suggested reading? That %matplotlib looks to me like iPython "magic" -- yes, that's the official name for it. It's not real Python code, and won't run in a regular Python interpreter like IDLE. IPython is a custom Python interactive interpreter. As well as running regular Python code, it includes special syntax for magic such as: %cd %run %bg and many more. http://ipython.org/ipython-doc/rel-0.10.2/html/interactive/reference.html#magic You could try installing iPython and running the tutorial examples in that, or perhaps finding a better tutorial that actually bothers to mention what it needs to run. (You have read the tutorial from the beginning, yes?) -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Mike S <mscir@yahoo.com> |
|---|---|
| Date | 2016-01-29 00:10 -0800 |
| Message-ID | <n8f6l7$pcv$1@dont-email.me> |
| In reply to | #102218 |
On 1/28/2016 11:57 PM, Steven D'Aprano wrote: > On Fri, 29 Jan 2016 06:04 pm, Mike S wrote: > >> %matplotlib inline >> >> I get an error on the last line. I am running this code in Idle Python >> 3.4.4 Shell... >> >> Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32 >> bit (Intel)] on win32 >> Type "copyright", "credits" or "license()" for more information. >> >>> import numpy as np >> >>> import pandas as pd >> >>> import random >> >>> import matplotlib.pyplot as plt >> >>> %matplotlib inline >> SyntaxError: invalid syntax >> >> What am I doing wrong? Suggested reading? > > That %matplotlib looks to me like iPython "magic" -- yes, that's the > official name for it. It's not real Python code, and won't run in a regular > Python interpreter like IDLE. > > IPython is a custom Python interactive interpreter. As well as running > regular Python code, it includes special syntax for magic such as: > > %cd > %run > %bg > > and many more. > > http://ipython.org/ipython-doc/rel-0.10.2/html/interactive/reference.html#magic > > You could try installing iPython and running the tutorial examples in that, > or perhaps finding a better tutorial that actually bothers to mention what > it needs to run. > > (You have read the tutorial from the beginning, yes?) Thank you Chris and Steven, I'll see if I can get iPython running and do a tutorial.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web