-
Notifications
You must be signed in to change notification settings - Fork 260
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
Unable to execute code using Jupyter as interpreter #1414
Comments
Hi, Just to check if the problem comes from elpy or python.el: you can deactivate elpy ( If it is still not working, my best guess would be python.el having trouble parsing jupyter output. What kind of output do you have when running |
Hi, Thanks for responding. Ive just loaded emacs purely with the config file as specified above. Confirmed that the problem is still occurring with elpy. After disabling elpy as you suggested, I opened a shell which loaded the jupyter console and it is now working, seemingly without issue. I can run code using Is there any further information that I can provide? |
Ok, What you can try to do is enabling debug ( |
Ok, so I've gone through and enabled
Any clues? |
If Emacs doesn't hang or throw any error during the first step (your point 1), I would think the code is correctly send to the shell, but there is something unexpected in the shell output that make Emacs parsing fail. I still have some ideas of things you can try to get us some more information:
|
Ok so having re-confirmed the problem persists, the results of your suggestions are the following (restarting emacs from fresh each time):
Subsequently running
Does any of that make sense to you? |
The fact that everything works fine when you are using Could you try running this function from a freshly opened python script, and paste the result: (defun elpy-debug ()
(interactive)
(let* ((bufname (format "*%s*" (python-shell-get-process-name nil)))
(proc (get-buffer-process bufname))
(default-directory (or (and elpy-shell-use-project-root
(elpy-project-root))
default-directory)))
(message "==================")
(message "=== Elpy debug ===")
(message "==================")
(message "bufname: %s" bufname)
(message "proc: %s" proc)
(message "elpy-shell-use-project-root: %s" elpy-shell-use-project-root)
(message "(elpy-project-root): %s" (elpy-project-root))
(message "default-directory: %s" default-directory)
(message "(python-shell-parse-command): %s" (python-shell-parse-command))
)) As a temporary workaround, putting the following code in your (defun elpy-shell-get-or-create-process (&optional sit)
"Get or create an inferior Python process for current buffer and return it.
If SIT is non-nil, sit for that many seconds after creating a
Python process. This allows the process to start up."
(let* ((bufname (format "*%s*" (python-shell-get-process-name nil)))
(proc (get-buffer-process bufname)))
(if proc
proc
(run-python (python-shell-parse-command) nil t)
(when sit (sit-for sit))
(get-buffer-process bufname)))) |
I also had this issue, and it was solved after including the |
Thanks for the feedback. I managed to reproduce this issue (from time to time). @Gijs-Koot, could you tell me if it solve your issue as well ? Maybe I could add a fix in Elpy so it wont bother anyone else. |
I've tried this by putting the |
hum... It could be that we are sending code to the shell too quickly after its creation. (defun elpy-shell-get-or-create-process (&optional sit)
"Get or create an inferior Python process for current buffer and return it.
If SIT is non-nil, sit for that many seconds after creating a
Python process. This allows the process to start up."
(let* ((bufname (format "*%s*" (python-shell-get-process-name nil)))
(proc (get-buffer-process bufname)))
(if proc
proc
(unless (executable-find python-shell-interpreter)
(error "Python shell interpreter `%s' cannot be found. Please set `python-shell-interpreter' to a valid python binary."
python-shell-interpreter))
(let ((default-directory
Does it ? (cond ((eq elpy-shell-starting-directory 'project-root)
(or (elpy-project-root)
default-directory))
((eq elpy-shell-starting-directory 'current-directory)
default-directory)
((stringp elpy-shell-starting-directory)
(file-name-as-directory
(expand-file-name elpy-shell-starting-directory)))
(t
(error "Wrong value for `elpy-shell-starting-directory', please check this variable documentation and set it to a proper value")))))
(run-python (python-shell-parse-command) nil t))
(when sit (sit-for sit))
(when (elpy-project-root)
(with-current-buffer bufname
(add-hook 'python-shell-first-prompt-hook
(lambda ()
(python-shell-send-string-no-output
(format "import sys;sys.path.append('%s');del sys"
(elpy-project-root))))
nil t)))
(get-buffer-process bufname)))) If it does for you I'll update the code. |
Sorry for not getting back to this earlier, your message got buried. I looked at the referenced issue #1712 and it seems you have figured out and fixed this situation. Thank you for this work! |
I suppose I can close this then. I suspected this to be at the origin of other problems, so I had to merge it quickly. |
Hello!
I am having issues getting my elpy configuration to work smoothly, and I was hoping somebody here could help.
For starters, I am running GNU emacs 26.1 on MacOS 10.13.5 (High Sierra), installed via homebrew. I am running a python 3.6 installation from the anaconda distribution.
My problem is that with jupyter set up as the interpreter, I seem to be unable to run any code. The issue exhibits itself in two ways:
C-c C-z
, then type a simple line of code next to the In [1]: prompt, hit return and nothing happens.C-c C-c
, emacs will either open the console and consequently do nothing, or, if the console was already running, emacs simply freezes up and I need to terminate emacs.If I remove the section that sets jupyter as my interpreter, the regular python interpreter executes the code as expected.
So, any suggestions are welcome.
Result of
(elpy-config)
Elpy configuration in my init.el
The text was updated successfully, but these errors were encountered: