Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs 27 json-read: JSON readtable error: 76 #301

Closed
thriveth opened this issue Nov 21, 2020 · 12 comments · Fixed by #418
Closed

Emacs 27 json-read: JSON readtable error: 76 #301

thriveth opened this issue Nov 21, 2020 · 12 comments · Fixed by #418

Comments

@thriveth
Copy link

Trying to move from ob-ipython to emacs-jupyter, I am having trouble getting it to run.

My main environment that I wish to work from is Anaconda on a Linux machine.
I do a minimal install of emacs-jupyter with use-package:

(use-package emacs-jupyter
  :ensure t
  )

Emacs claims it installed jupyter just fine, but when trying to run the REPL, I get the error message:

json-read: JSON readtable error: 76 

...rather cryptic, I think. I have not een able to find out whether emacs-jupyter finds the Anaconda jupyter kernels and interpreters, but org-babel also does not understand any jupyter-XXX named kernels even though I did

  (org-babel-do-load-languages
   'org-babel-load-languages
   '((R . t) 
     (python . t) 
     ;;(ipython . t) 
     (latex . t)
     (ditaa . t)
     (shell . t)
     (jupyter . t)
     ))

  (org-babel-jupyter-override-src-block 'python)

...with no luck.
What am I doing wrong?

@gmoutso
Copy link

gmoutso commented Nov 24, 2020

Can you try loading package jupyter instead of emacs-jupyter? I use the following

(use-package jupyter
  :after (ob-jupyter ob-python)
  :config
  (setq jupyter-api-authentication-method 'password)
  (setq jupyter-eval-use-overlays nil)
  (setq org-babel-default-header-args:jupyter-python '((:session . "/jpy:localhost#8888:py")
                                                       (:kernel . "conda-env-edge-py")
                                                       (:async . "yes")
						       (:pandoc t)))
  (add-to-list 'savehist-additional-variables 'jupyter-server-kernel-names)
  (setq ob-async-no-async-languages-alist '("jupyter-python"))
  (add-to-list 'org-structure-template-alist '("j" . "src jupyter-python")))

@thriveth
Copy link
Author

thriveth commented Nov 27, 2020

Thanks @gmoutso , I tried basically copying your setup and removing my own, and tried to M-x jupyter-run-repl, but again, I get a "JSON readtable error: 76".

When I attempt to create an org source block and press C-c ' , I get the error "no such language mode: jupyter-python-mode".

@gmoutso
Copy link

gmoutso commented Dec 1, 2020

Can you also load the libraries ob-jupyter and ob-python with use-package or require before you C-c ' the block?

The "no such language mode" might mean you need

(org-babel-do-load-languages
 'org-babel-load-languages
 '( (C . t) (python . t) (emacs-lisp . t) (dot . t) (plantuml . t)
   (jupyter . t)
   ))

I don't know why I don't need it (loaded by ob-jupyter?).

Can you remove the org-babel-default-header-args:jupyter-python line that I wrote above (you would not have a ipykernel called conda-env-edge-py like I have anyway) ?

@gmoutso
Copy link

gmoutso commented Dec 4, 2020

Can you run jupyter kernelspec list --json on the command line?

@Jason-S-Ross
Copy link

I had the same issue. Running jupyter kernelspec list --json showed a warning message:

[ListKernelSpecs] WARNING | Config option `kernel_spec_manager_class` not recognized by `ListKernelSpecs`.
{
  "kernelspecs": {
    "python3": {
      "resource_dir": "/home/jason/anaconda3/share/jupyter/kernels/python3",
      "spec": {
        "argv": [
          "/home/jason/anaconda3/bin/python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {}
      }
    }
  }
}

It turned out there was a config file ~/anaconda3/etc/jupyter/jupyter_config.json that had a bad configuration line in it. It's probably a result of a configuration option getting removed in a new version of nb_conda_kernels or something. Getting rid of that line made the warning go away and suddenly I don't get the error 76.

Calling jupyter kernelspec list --json --log-level=50 in the jupyter-available-kernelspecs returns the JSON without the warning message, fyi.

@thriveth
Copy link
Author

@Jason-S-Ross The same was the root of my problem, it seems!

I wonder if this is something that would be worth adding to the documentation? In general, how to set it up with Conda? It's not super hard when one knows how to, but it can be pretty hard to figure out, and especially, this bug was really hard to track down.

@BuddhiLW
Copy link

I don't know why I have this kind of error, with other packages, also.

For example, org-roam-capture gives me:
user-error: JSON readtable error: 122.

Very annoying. That doesn't happen in my laptop, and pretty much it's the same linux and config file distributions. Although both have it's tweaks. Nothing I believe should have to with JSON handling.

I made sure to delete json related packages, indium, and javascript related modes. No success.

@BuddhiLW
Copy link

It's a little strange, but the problem is the following:

pic-selected-210620-0700-47

Install jupyter in your system, and guarantee it's usable by your emacs environment.

It's a chain of dependencies breakage.

The solution I found in this thread syl20bnr/spacemacs#9941

@Awannaphasch2016
Copy link

Awannaphasch2016 commented May 18, 2022

Try my fix solution below

its the following code that cause error

(jupyter-read-plist-from-string
                       (or (jupyter-command "kernelspec" "list" "--json")
                           (error "Can't obtain kernelspecs from jupyter shell command")

you can find this in emacs-jupyter/jupyter-kernelspec.el

(defun jupyter-available-kernelspecs (&optional refresh)
  "Get the available kernelspecs.
Return an alist mapping kernel names to (DIRECTORY . PLIST) pairs
where DIRECTORY is the resource directory of the kernel and PLIST
is its kernelspec plist.  The alist is formed by parsing the
output of the shell command

    jupyter kernelspec list

By default the available kernelspecs are cached.  To force an
update of the cached kernelspecs, give a non-nil value to
REFRESH.

If the `default-directory' is a remote directory, return the
mapping for the kernelspecs on the remote host.  In this case,
each DIRECTORY will be a remote file name."
  (let ((host (or (file-remote-p default-directory) "local")))
    (or (and (not refresh) (gethash host jupyter--kernelspecs))
        (let ((specs (plist-get
                      (jupyter-read-plist-from-string
                       (or (jupyter-command "kernelspec" "list" "--json")
                           (error "Can't obtain kernelspecs from jupyter shell command")))
                      :kernelspecs)))
          (puthash
           host (cl-loop
                 for (name spec) on specs by #'cddr
                 for dir = (concat (unless (equal host "local") host)
                                   (plist-get spec :resource_dir))
                 collect (cons (substring (symbol-name name) 1)
                               (cons dir (plist-get spec :spec))))
           jupyter--kernelspecs)))))

JSON readtable error: 76 occurs when

 (jupyter-command "kernelspec" "list" "--json") 

output warning as followed

[ListKernelSpecs] WARNING | Kernel Provisioning: The 'local-provisioner' is not found.  This is likely due to the presence of multiple jupyter_client distributions and a previous distribution is being used as the source for entrypoints - which does not include 'local-provisioner'.  That distribution should be removed such that only the version-appropriate distribution remains (version >= 7).  Until then, a 'local-provisioner' entrypoint will be automatically constructed and used.
The candidate distribution locations are: ['/home/awannaphasch2016/anaconda3/envs/py38/lib/python3.8/site-packages/jupyter_client-6.1.12.dist-info', '/home/awannaphasch2016/anaconda3/envs/py38/lib/python3.8/site-packages/jupyter_client-7.1.0.dist-info']
{
  "kernelspecs": {
    "python3": {
      "resource_dir": "/home/awannaphasch2016/anaconda3/envs/py38/share/jupyter/kernels/python3",
      "spec": {
        "argv": [
          "/home/awannaphasch2016/anaconda3/envs/py38/bin/python",
          "-m",
          "ipykernel_launcher",
          "-f",
          "{connection_file}"
        ],
        "env": {},
        "display_name": "Python 3 (ipykernel)",
        "language": "python",
        "interrupt_mode": "signal",
        "metadata": {
          "debugger": true
        }
      }
    }
  }
}

follow the instruction and only keep jupyter version > 7 will remove the warning and jupyter-read-plist-from-string will no longer produce error.

@darosio
Copy link

darosio commented Jun 7, 2022

I am hitting this after upgrade the system (archlinux) jupyter_client 7.3.1 -> 7.3.2.

@mk0417
Copy link

mk0417 commented Jun 7, 2022

I also had the problem after the upgrade of jupyter_client from 7.3.1 to 7.3.2. There is an issue in version 7.3.2 and it is fixed in version 7.3.3 (see links below). I can start jupyter kernel after use the latest version of jupyter_client.

jupyter/jupyter_client#800
jupyter/jupyter_client#801

@darosio
Copy link

darosio commented Jun 7, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants