elpy
elpy copied to clipboard
__init__() got an unexpected keyword argument 'source'
Summary
Error Message
__init__() got an unexpected keyword argument 'source'
Traceback (most recent call last):
File "/Users/slucx/.emacs.d/elpa-27.1/elpy-1.35.0/elpy/jedibackend.py", line 368, in run_with_debug
script = jedi.Script(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'source'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/slucx/.emacs.d/elpa-27.1/elpy-1.35.0/elpy/jedibackend.py", line 401, in run_with_debug
script = jedi.Script(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'source'
Jedi Debug Information
Jedi did not emit any debug info.
Reproduction:
import jedi
source = '''\
import zmq
import time
import os
context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind('tcp://126.0.0.1:5555')
while True:
msg = socket.recv()
print(f'received request: {msg}')
time.sleep(1)
socket.send(b'world')
'''
script = jedi.Script(source=source, line=14, column=0, path='/Users/slucx/scratch/tzmq/serv.py', encoding='utf-8', environment=None)
script.goto_definitions()
My configuration
mac osx 10.13.6
Result of (elpy-config)
Emacs.............: 27.1
Elpy..............: 1.35.0
Virtualenv........: custom (/Users/slucx/.venv/custom)
Interactive Python: python 3.9.0 (/Users/slucx/.venv/custom/bin/python)
RPC virtualenv....: custom (/Users/slucx/.venv/custom)
Python...........: python 3.9.0 (/Users/slucx/.venv/custom/bin/python)
Jedi.............: 0.18.0
Rope.............: Not found (0.18.0 available)
Autopep8.........: 1.5.4
Yapf.............: Not found (0.30.0 available)
Black............: Not found (20.8b1 available)
Syntax checker....: flake8 (/Users/slucx/.venv/custom/bin/flake8)
Elpy configuration in my init.el
;;; Code:
(require-package 'elpy)
(defun py-workon (name)
"Activate a virtual environment from $WORKON_HOME.
If the virtual environment NAME is already active, this function
does not try to reactivate the environment."
(interactive
(list
(completing-read "Work on: " (pyvenv-virtualenv-list)
nil t nil 'pyvenv-workon-history nil nil)))
(pyvenv-workon name)
(setq elpy-rpc-virtualenv-path
(expand-file-name name (getenv "WORKON_HOME"))))
(with-eval-after-load 'python
;; jedi flake8 autopep8 importmagic
(unless (or (is-buffer-file-temp)
(not buffer-file-name)
;; embed python code in org file
(string= (file-name-extension buffer-file-name) "org"))
(elpy-enable)
(setenv "WORKON_HOME" "~/.venv")
(py-workon "custom")
;; (setq elpy-rpc-virtualenv-path)
;; If you don't like any hint or error report from elpy,
;; set `elpy-disable-backend-error-display' to t.
(setq elpy-disable-backend-error-display nil))
;; emacs 24.4+
(setq electric-indent-chars (delq ?: electric-indent-chars)))
(provide 'init-python)
;;; init-python ends here
@slucx (and any others who may run into this): I recently encountered a similar issue, using jedi 0.18.1 (vs. 0.18.0 which you were using in 2020). I had installed elpy (1.35.0 - same as you) from https://stable.melpa.org/#/elpy After updating elpy to latest (20220627.1416) at https://melpa.org/#/elpy I no longer encounter the issue.
I was clued by #1964 (thanks @max0x7ba)
I switched to using lsp
instead, it works marvelously.