[英]jupyter notebook python version 2.7.13 (print invalid syntax error)
Hi I have a Jupyter Notebook, with python 2.7.13 and it worked fine all along. 嗨,我有一个Jupyter笔记本,python 2.7.13,它一直很好。 But starting today it shows strange behaviour. 但从今天开始它显示出奇怪的行为。
when I do this in a fresh notebook Python 2: 当我在一个新的笔记本Python 2中这样做:
print 'hello'
it returns this: 它返回:
File "<ipython-input-1-bfbe230352b8>", line 1
print 'hello'
^
SyntaxError: invalid syntax
It was working ok till yesterday and today I restarted the computer and this happens. 它工作正常,直到昨天,今天我重新启动计算机,这发生了。
Any reasons? 有什么原因? How to fix? 怎么修?
I have checked anaconda, spyder, command prompt... everywhere else is ok with 2.7.13 我检查过anaconda,spyder,命令提示符......其他地方都可以使用2.7.13
print ('hello')
works but I don't want this.. all my code is in Python 2. print ('hello')
有效,但我不想这样..我的所有代码都在Python 2中。
I have now tracked the problem to be caused by the extension. 我现在已经跟踪了扩展引起的问题。 Once I rename this file C:\\Users\\X\\.jupyter\\nbconfig\\notebook.json
to something else and reopen jupyter notebook, the print works as expected. 一旦我将此文件C:\\Users\\X\\.jupyter\\nbconfig\\notebook.json
_ notebook.json重命名为其他内容并重新打开jupyter notebook,打印就会按预期工作。
However, I do need the extensions at least the key ones I use regularly. 但是,我确实需要扩展至少我经常使用的关键扩展。 I don't know which one to disable. 我不知道禁用哪一个。 I didn't know how to track the culprit without going through each one by one. 我不知道怎么跟踪罪魁祸首而不经过每一个人。 Also, as far as I can remember, all the extensions I have been using for few weeks already without any issues. 此外,据我所知,我已经使用几周的所有扩展已经没有任何问题。
These are the contents of the notebook.json file. 这些是notebook.json文件的内容。
{
"load_extensions": {
"toc2/main": true,
"Runtools": true,
"collapsible_headings/main": true,
"codefolding/main": true,
"varInspector/main": true,
"runtools/main": true,
"runtools": true
},
"collapsible_headings": {
"add_button": true,
"add_insert_header_buttons": true
}
}
After trial and error with disabling one every time, restart and check.. I have now solved the problem by setting this line to false, it now works. 在每次禁用一次的试验和错误之后,重新启动并检查..我现在通过将此行设置为false来解决问题,现在它可以正常工作。 The problem is with variable inspector extension. 问题在于可变检查员扩展。
"varInspector/main": false,
Sometimes the jupyter required a restart and sometime it didn't. 有时jupyter需要重启,有时则没有。 Just opening the .ipynb file was enough to test. 只需打开.ipynb文件即可进行测试。
I have the same extension running in my office computer, which has no issues. 我的办公室计算机上运行了相同的扩展程序,没有任何问题。
If someone could really put in the comments for the cause and a solution for permanent fix of this problem will be great. 如果有人真的可以为这个问题提出意见,那么永久解决这个问题的解决方案就会很棒。
Could you please try with reloading sys like below ? 你可以尝试重新加载sys如下吗?
import sys
reload(sys)
print 'hello'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.