问题
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)
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
回答1:
Wow, well I just tried something as an afterthought and it worked. Change the interpreter to Python 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.
EDIT: 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.
来源:https://stackoverflow.com/questions/34731262/running-a-very-simple-bokeh-server-example-using-pycharm-no-json-object-could