You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
json-read: JSON readtable error with python 3.6.3 #135
I think I figured this out, at least on my system (latest version of ob-ipython, ipython version 6.1.0, python version 3.6.2 with Anaconda). I got this error too, and I fixed it by using exec-path-from-shell to set the PATH correctly. Install that from MELPA and put this in your init file before loading ob-ipython:
I think the reason this happens is because it uses jupyter to get a JSON output of the kernels, but it runs that via shell-command, which doesn't use the exec-path variable the rest of Emacs uses. You should be good if M-! jupyter -h returns a normal help entry and not zsh:1:command not found: 'jupyter' or equivalent.
This is probably a documentation problem moreso than a code problem, as I'm not sure how you're supposed to be able to divine where the jupyter executable is in elisp.
We must have different errors with the same error message. Can you try invoking toggle-debug-on-errorand then running it, or if that doesn't work trying toggle-debug-on-entry with json-read?
Once I comment the line that makes bash throw a warning, things work!
@gregsexton Maybe a regexp to select the bit that begins with {\n and ends with \n") before passing it to json-read would do the trick? Perhaps you could catch the error and display the string so it's clear what json-read is choking on?
There are also seem to be problems with it killing the jupyter process. I have to kill it manually otherwise I get errors from ZMQ saying the port is already in use.
I get a buffer called *ob-ipython-kernel-default* with some output from starting a jupyter console. It seems that json-read is being run on this buffer which doesn't contain anything that looks like JSON:
Jupyter console 5.2.0
Python 3.6.2 (default, Sep 28 2017, 13:58:54)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
Set debug-on-entry to stop at ob-ipython--collect-json. When it does hit c to continue, do this twice and it should show the string it's trying to read. That'll tell you what it's choking on
I've tried using edebug and stepping through. The difficulty seems to be that in ob-ipython--execute-request it runs ob-ipython--collect-json in a temporary buffer. I can't figure out how to look at what's being written in the temp buffer, though.
OK, I finally figured it out. It's not easy to debug something that uses with-temp-buffer, but eventually I figured out I could manually repalce that with a real buffer and see the output. Turns out my ipython prints an error about being run in a virtualenv which is not proper JSON. So now I need to figure out how to suppress that warning (which I think is safe).
I succumbed to installing jupyter/ipython within each virtualenv and now there is no error and it works.
when I use ob-ipython in Emacs launched from a shell with an active virtualenv (using pyenv) I get the same json-readtable error. My code runs on the kernel though, I could verify it by using the interactive session with C-c C-v C-z. However I don't get any output in the result block.
Now when I launch Emacs from my basic system environment and then use pyen-mode-set to activate the exact same virtualenv from within Emacs, everything works fine.
I am happy with that but still curious to understand what exactly is going wrong.
I added @dangirsh 's fix dangirsh@df13b94 to the ob-iython--execute-request function to be able to have a look at the json ob-ipython and the kernel use to communicate and I finally found where the problem was in my case : the kernel throws a warning message that is not json formated.
/home/teddd/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py:763: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. warn("Attempting to work in a virtualenv. If you encounter problems, please "
Thus when reading this message, ob-ipython--collect-json returns an error number being the first letter encountered in the error message in decimal form. (In my case error 47 corresponds to the "/" character) This explains why this number is so random and cryptic.
As I see it the problem is not only virtualenvs, but also the way ob-ipython handles outputs coming from the kernel. This non json message should clearly be redirected to the error/warning buffer. Maybe there should be a filter ? Is there already such a function somewhere else in the code ? How are error messages normaly handled @gregsexton ?
Of course the simplest way would be to just run pyenv or get the PATH from the shell and not have any error message, but this wouldn't make the program more robust. Who knows if the next version of Jupyter doesn't throw wierd stuff on our poor json-read ?
Currently, my ob-ipython setup returned to having similar error as discussed in this issue when I attempt to run a ipython code block from within a org mode file. If others think I should open a new issue, I will do so; however, after reading the comments under this issue I felt that my error was similar enough to warrant posting a comment here.
Now to the actual error message I am seeing:
error in process sentinel: json-read: JSON readtable errorxo error in process sentinel: JSON readtable error
When toggling debug on error, I get the following backtrace:
emacs --version
GNU Emacs 25.3.1
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
I have the most recent version of ob-ipython installed directly from the git repository and I am running a openSUSE Leap 15.0 linux machine.
I have tried some of the solutions proposed in this issue to workaround this error but none of them worked in my case. The only thing that helped is to add (exec-path-from-shell-initialize) in my emacs configuration before loading ob-ipython which only caused no backtrace to be generated while still displaying the error json-read: JSON readtable error.
If anyone has any ideas for how I can fix this issue I am experiencing, I would appreciate the help.
@jchkoch your error seem to be different, but the problem might be the same. The problem is that this error message doesn't tell a lot about where the problem reside. Generally though it is a problem of the way ob-ipython and your python environment interact.
Have you checked if the env is well set in your org file ? You can try shell-command RET python --version RET and the others. If there is a problem here, using pyenv and its emacs plugin might be a solution.
To address your problem more specifically, I advice you to use this hack dangirsh@df13b94 to be able to have a look at the json and understand what in it causes the reader to crash.
I also had good results using edebug. It is implemented in Emacs and allows you to follow step by step the program in the elisp source code, knowing what data is coming in and out of each step. You could thus see more precisely where it crashes in the json-read function. But my guess is just that the json is badly formatted, have a look a it first :)
The json-readtable error that I reported 2 days ago (#135 (comment)) disappeared when I restarted emacs today. So far, I have not ascertained why the issue disappeared. Anyway, thanks for the reply @theottm and I will keep this in mind if the error ever comes back.
I was getting a similar problem, but using edebug revealed that I was getting extra messages after the JSON response rather than before. I extended the solution in #135 (comment) to remove anything around or between top-level JSON objects in the response, which seems to be working for me:
Activity
dcherian commentedon Nov 13, 2017
I had this problem and had to downgrade.
Can we have a section in README that mentions the latest version of python this has been tested on?
andrewsanchez commentedon Nov 13, 2017
Neither downgrading with
conda install python=3.5(resulted in 3.5.4) norconda install python=3.5.2worked for me.dcherian commentedon Nov 13, 2017
Oh I meant downgrade ob-ipython. I haven't tried with python 3.5
dcherian commentedon Nov 17, 2017
Can someone who's using the latest ob-ipython please comment with versions of python / ipython / jupyter they're using?
nicholas-miklaucic commentedon Nov 29, 2017
I think I figured this out, at least on my system (latest version of
ob-ipython,ipythonversion 6.1.0,pythonversion 3.6.2 with Anaconda). I got this error too, and I fixed it by using exec-path-from-shell to set the PATH correctly. Install that from MELPA and put this in your init file before loading ob-ipython:I think the reason this happens is because it uses jupyter to get a JSON output of the kernels, but it runs that via
shell-command, which doesn't use theexec-pathvariable the rest of Emacs uses. You should be good ifM-! jupyter -hreturns a normal help entry and notzsh:1:command not found: 'jupyter'or equivalent.This is probably a documentation problem moreso than a code problem, as I'm not sure how you're supposed to be able to divine where the
jupyterexecutable is in elisp.dcherian commentedon Dec 3, 2017
Hmm... I've always had
exec-path-from-shellconfigured and running.M-! jupyter -hreturns a normal help entry too.Is there a way to see the string
json-readis having trouble decoding? My elisp isn't good enough to figure it out.nicholas-miklaucic commentedon Dec 3, 2017
We must have different errors with the same error message. Can you try invoking
toggle-debug-on-errorand then running it, or if that doesn't work tryingtoggle-debug-on-entrywithjson-read?dcherian commentedon Dec 4, 2017
@nicholas-miklaucic Thanks!
Using
debug-on-entryshowed this (newlines added for clarity):Once I comment the line that makes bash throw a warning, things work!
@gregsexton Maybe a regexp to select the bit that begins with
{\nand ends with\n")before passing it tojson-readwould do the trick? Perhaps you could catch the error and display the string so it's clear whatjson-readis choking on?georgek commentedon Dec 4, 2017
This isn't working at all for me. Using Python 3.6.2 and getting the same JSON read table error. This is me trying to run the example:
Debugger entered--Lisp error: (json-readtable-error)
There are also seem to be problems with it killing the jupyter process. I have to kill it manually otherwise I get errors from ZMQ saying the port is already in use.
nicholas-miklaucic commentedon Dec 4, 2017
Try invoking
toggle-debug-on-entrywithjson-readto see what it's choking on: your error seems different as it's for running code, AFAIK.dcherian commentedon Dec 4, 2017
You'll also want to make sure that jupyter isn't writing any warnings also. I had to remove those too.
georgek commentedon Dec 5, 2017
I get a buffer called
*ob-ipython-kernel-default*with some output from starting a jupyter console. It seems that json-read is being run on this buffer which doesn't contain anything that looks like JSON:dcherian commentedon Dec 5, 2017
@georgek That's how it looks like when it works.
Set
debug-on-entryto stop atob-ipython--collect-json. When it does hitcto continue, do this twice and it should show the string it's trying to read. That'll tell you what it's choking onEDIT: Not sure that will work actually but you can try. I found the second answer here helpful: https://stackoverflow.com/questions/3257480/how-to-debug-elisp#3258205
georgek commentedon Dec 5, 2017
I've tried using edebug and stepping through. The difficulty seems to be that in
ob-ipython--execute-requestit runsob-ipython--collect-jsonin a temporary buffer. I can't figure out how to look at what's being written in the temp buffer, though.georgek commentedon Dec 5, 2017
OK, I finally figured it out. It's not easy to debug something that uses
with-temp-buffer, but eventually I figured out I could manually repalce that with a real buffer and see the output. Turns out my ipython prints an error about being run in a virtualenv which is not proper JSON. So now I need to figure out how to suppress that warning (which I think is safe).I succumbed to installing jupyter/ipython within each virtualenv and now there is no error and it works.
12 remaining items
nanounanue commentedon Dec 31, 2017
@dcherian What do you mean? Could you be more specific?
aayusuff commentedon Dec 31, 2017
You can set ob-ipython-command to the path of jupyter. e,g
(setq ob-ipython-command "/home/name/miniconda3/bin/jupyter") . You can then restart emacs.
nanounanue commentedon Dec 31, 2017
@aayusuff I am using
pyenv-modefor that.ob-ipythonis picking the right path. But I will try your suggestion anyway.Don't error if jupyter not found while auto-configuring kernels
Use intermediate file between Emacs and client.py to prevent misc Emacs
theottm commentedon Sep 23, 2018
Hello everyone,
when I use ob-ipython in Emacs launched from a shell with an active virtualenv (using pyenv) I get the same json-readtable error. My code runs on the kernel though, I could verify it by using the interactive session with C-c C-v C-z. However I don't get any output in the result block.
Now when I launch Emacs from my basic system environment and then use pyen-mode-set to activate the exact same virtualenv from within Emacs, everything works fine.
I am happy with that but still curious to understand what exactly is going wrong.
I added @dangirsh 's fix dangirsh@df13b94 to the ob-iython--execute-request function to be able to have a look at the json ob-ipython and the kernel use to communicate and I finally found where the problem was in my case : the kernel throws a warning message that is not json formated.
/home/teddd/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py:763: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv. warn("Attempting to work in a virtualenv. If you encounter problems, please "Thus when reading this message, ob-ipython--collect-json returns an error number being the first letter encountered in the error message in decimal form. (In my case error 47 corresponds to the "/" character) This explains why this number is so random and cryptic.
As I see it the problem is not only virtualenvs, but also the way ob-ipython handles outputs coming from the kernel. This non json message should clearly be redirected to the error/warning buffer. Maybe there should be a filter ? Is there already such a function somewhere else in the code ? How are error messages normaly handled @gregsexton ?
Of course the simplest way would be to just run pyenv or get the PATH from the shell and not have any error message, but this wouldn't make the program more robust. Who knows if the next version of Jupyter doesn't throw wierd stuff on our poor json-read ?
jchkoch commentedon Sep 25, 2018
Hello everyone,
Currently, my ob-ipython setup returned to having similar error as discussed in this issue when I attempt to run a ipython code block from within a org mode file. If others think I should open a new issue, I will do so; however, after reading the comments under this issue I felt that my error was similar enough to warrant posting a comment here.
Now to the actual error message I am seeing:
error in process sentinel: json-read: JSON readtable errorxo error in process sentinel: JSON readtable errorWhen toggling debug on error, I get the following backtrace:
Furthermore, the following is additional information regarding package versions in my current setup:
jupyter-console --version 5.2.0jupyter --version 4.4.0ipython --version 6.4.0python --version Python 3.6.4I have the most recent version of
ob-ipythoninstalled directly from the git repository and I am running aopenSUSE Leap 15.0linux machine.I have tried some of the solutions proposed in this issue to workaround this error but none of them worked in my case. The only thing that helped is to add
(exec-path-from-shell-initialize)in my emacs configuration before loading ob-ipython which only caused no backtrace to be generated while still displaying the errorjson-read: JSON readtable error.If anyone has any ideas for how I can fix this issue I am experiencing, I would appreciate the help.
theottm commentedon Sep 26, 2018
@jchkoch your error seem to be different, but the problem might be the same. The problem is that this error message doesn't tell a lot about where the problem reside. Generally though it is a problem of the way ob-ipython and your python environment interact.
Have you checked if the env is well set in your org file ? You can try shell-command RET python --version RET and the others. If there is a problem here, using pyenv and its emacs plugin might be a solution.
To address your problem more specifically, I advice you to use this hack dangirsh@df13b94 to be able to have a look at the json and understand what in it causes the reader to crash.
I also had good results using edebug. It is implemented in Emacs and allows you to follow step by step the program in the elisp source code, knowing what data is coming in and out of each step. You could thus see more precisely where it crashes in the json-read function. But my guess is just that the json is badly formatted, have a look a it first :)
Good luck !
jchkoch commentedon Sep 27, 2018
The json-readtable error that I reported 2 days ago (#135 (comment)) disappeared when I restarted emacs today. So far, I have not ascertained why the issue disappeared. Anyway, thanks for the reply @theottm and I will keep this in mind if the error ever comes back.
theottm commentedon Sep 29, 2018
glad to hear it !
Disable ob-ipython
Don't error if jupyter not found while auto-configuring kernels
ganesh-krishnan commentedon Mar 2, 2019
I was seeing the same error. #135 (comment) worked. Thank you!
thcoffee-msft commentedon Apr 1, 2019
I was getting a similar problem, but using edebug revealed that I was getting extra messages after the JSON response rather than before. I extended the solution in #135 (comment) to remove anything around or between top-level JSON objects in the response, which seems to be working for me: