使用Pycharm运行一个非常简单的Bokeh Server示例-无法解码JSON对象 [英] Running a very simple Bokeh Server example using Pycharm - No JSON object could be decoded
问题描述
The following code is a very simple bokeh server example retrieved from the Specifying output_server section. It works and I get a Bokeh plot on my browser if I run bokeh serve
in one terminal and then this code in a desperate python shell
from bokeh.plotting import figure, show, output_server
p = figure(title="Server Plot")
p.circle([1, 2, 3], [4, 5, 6])
output_server("hover")
show(p)
但是,当我尝试从pycharm运行此代码时,会得到以下回溯:
However, when I try to run this code from pycharm I get the following traceback:
/usr/bin/python2.7 /home/cornelis/PycharmProjects/BrainImageAnalyzer/BokehTest.py
Using saved session configuration for http://localhost:5006/
To override, pass 'load_from_config=False' to Session
Traceback (most recent call last):
File "/home/cornelis/PycharmProjects/BrainImageAnalyzer/BokehTest.py", line 16, in <module>
output_server("hover")
File "/usr/local/lib/python2.7/dist-packages/bokeh/io.py", line 169, in output_server
docname, session=session, url=url, name=name, clear=clear
File "/usr/local/lib/python2.7/dist-packages/bokeh/state.py", line 222, in output_server
self._session.use_doc(docname)
File "/usr/local/lib/python2.7/dist-packages/bokeh/session.py", line 455, in use_doc
self.docid = self.find_doc(name)
File "/usr/local/lib/python2.7/dist-packages/bokeh/session.py", line 418, in find_doc
docs = self.userinfo.get('docs')
File "/usr/local/lib/python2.7/dist-packages/bokeh/session.py", line 373, in userinfo
self._userinfo = self.get_json(url)
File "/usr/local/lib/python2.7/dist-packages/bokeh/session.py", line 351, in get_json
return self.execute_json('get', url, headers=headers, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/bokeh/session.py", line 335, in execute_json
return get_json(resp)
File "/usr/local/lib/python2.7/dist-packages/bokeh/util/serialization.py", line 88, in get_json
return response.json()
File "/usr/lib/python2.7/dist-packages/requests/models.py", line 741, in json
return json.loads(self.text, **kwargs)
File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Related, though at the time of writing, no answer posted: Can't run Bokeh abstract rendering example - ValueError: No JSON could be decoded
推荐答案
哇,好吧,我只是事后尝试了一下,然后就奏效了.将解释器更改为Python 3.4.0
Wow, well I just tried something as an afterthought and it worked. Change the interpreter to Python 3.4.0
在Pycharm中,转到文件"->设置" 转到项目解释器选项卡 从下拉列表中将解释器"更改为3.4.0并应用.
In Pycharm, go to File -> Settings Go to the Project Interpreter tab From the drop-down list change the Interpreter to 3.4.0 and apply.
示例重新运行后,令我惊讶的是
Upon rerunning, much to my surprise, the example works.
我欢迎任何人修改此答案或在下面添加一个答案,以解释这是为什么的原因,因为据文档似乎告诉我,Bokeh支持2.7.
I welcome anyone to modify this answer or add one below that explains why this is because as far as the docs seem to be telling me, 2.7 is supported by Bokeh.
这篇关于使用Pycharm运行一个非常简单的Bokeh Server示例-无法解码JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!