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

ModuleNotFoundError: No module named 'jediepcserver' #347

Open
joefbkohler opened this issue Apr 27, 2020 · 12 comments
Open

ModuleNotFoundError: No module named 'jediepcserver' #347

joefbkohler opened this issue Apr 27, 2020 · 12 comments

Comments

@joefbkohler
Copy link

I'm working on OSX and when trying to start Jedi by running jedi:setup after a jedi:install-server, I get this error:

Error (jedi): 
================================
Failed to start Jedi EPC server.
================================

*** EPC Error ***
Server may raise an error. Use "M-x epc:pop-to-last-server-process-buffer RET" to see full traceback:
Traceback (most recent call last):
  File "/Users/jose.junior/.emacs.d/.python-environments/default/bin/jediepcserver", line 5, in <module>
    from jediepcserver import main
ModuleNotFoundError: No module named 'jediepcserver'

*** EPC Server Config ***
Server arguments: ("/Users/jose.junior/.emacs.d/.python-environments/default/bin/jediepcserver")
Actual command: /Users/jose.junior/.emacs.d/.python-environments/default/bin/jediepcserver
VIRTUAL_ENV envvar: nil

*** jedi-mode is disabled in #<buffer fetch_data.py> ***
Fix the problem and re-enable it.

*** You may need to run "M-x jedi:install-server". ***
This could solve the problem especially if you haven't run the command yet
since Jedi.el installation or update and if the server complains about
Python module imports.

I ran jedi:install-server and it installed everything under ~/.emacs.d/.python-environments. If I source ~/.emacs.d/.python-environments/default/bin/activate, and run python, I can import the jediepcserver module. But jedi:setup can't find the module. It seems that jedi:setup is not running in the correct environment.

For now I installed all jedi dependencies globally using pip and it is working, but it seems suboptimal and the jedi documentation even says it is not recommended.

Did I do something wrong? Is it some mac idiosyncrasy? Is it a bug?

@immerrr
Copy link
Collaborator

immerrr commented Apr 27, 2020

Yep, it is not recommended to use jedi requirements from the global env, but if it works for you, feel free.

What is the shebang for your jediepcserver script? Try running this:

$ head -n1 /Users/jose.junior/.emacs.d/.python-environments/default/bin/jediepcserver

@joefbkohler
Copy link
Author

The shebang is:

#!/usr/local/opt/python/bin/python3.7

@immerrr
Copy link
Collaborator

immerrr commented Apr 28, 2020

There have been reports of this shebang being created on OS X hosts (#346). As I don't have an OS X system available for testing, it's difficult to fix for me alone.

Would you be willing to troubleshoot this on your side?

@joefbkohler
Copy link
Author

Sure, I'll do what I can to help.

@immerrr
Copy link
Collaborator

immerrr commented Apr 29, 2020

Here's a snippet that will run jedi:install-server-block into a temporary virtualenv tracing all related parameters. Could you try that out and tell me what it prints in *Messages* buffer?

(defvar trace-indent 0)

(defun trace-function (fn-name orig-fun &rest args)
  (cl-incf trace-indent)
  (unwind-protect
      (let ((trace-prefix (make-string (* 2 trace-indent) (string-to-char "="))))
        (message "======%s %s called with args %S" trace-prefix fn-name args)
        (let ((res (apply orig-fun args)))
          (message "======%s %s returned %S" trace-prefix fn-name res)
          res))
    (cl-decf trace-indent)))


(defun remove-advices (fn-sym)
  (advice-mapc (lambda (func props) (advice-remove fn-sym func)) fn-sym))

(defun remove-single-advice (fn-sym func-to-remove)
  (advice-mapc (lambda (func props)
                 (when (equal func func-to-remove)
                   (advice-remove fn-sym func)))
               fn-sym))

(defun add-trace-function (fn-sym)
  (lexical-let*
      ((fn-sym fn-sym)
       (trace-fn (lambda (&rest args)
                   (apply #'trace-function
                          (format "Function %S" fn-sym)
                          args))))
    (advice-add fn-sym :around trace-fn)
    (list fn-sym trace-fn)))

(defun trace-jedi-install-server-block ()
  (let* ((jedi:environment-root "jedi-trace-install-server-block")
         (funcs-to-advise '(python-environment--blocking-process
                            python-environment-run-block
                            python-environment--deferred-process
                            call-process
                            deferred-process
                            jedi:install-server-block
                            jedi:install-server))
         advices)
    (unwind-protect
        (progn
          (mapc (lambda (fn-sym) (push (add-trace-function fn-sym) advices))
                funcs-to-advise)
          (when (python-environment-exists-p jedi:environment-root)
            (delete-directory (python-environment-root-path jedi:environment-root) 'recursive))
          (jedi:install-server-block))
      (mapc (lambda (advice-info) (apply #'remove-single-advice advice-info))
            advices))))

(trace-jedi-install-server-block)

@joefbkohler
Copy link
Author

Sorry I took so long to answer. Here are the results:

======== Function jedi:install-server-block called with args nil
========== Function python-environment-run-block called with args (("pip" "install" "--upgrade" "/Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/") "jedi-trace-install-server-block" nil)
============ Function python-environment--blocking-process called with args ("Making virtualenv at /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block" ("virtualenv" "--system-site-packages" "--quiet" "/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block"))
Making virtualenv at /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block (SYNC)...
============== Function call-process called with args ("virtualenv" nil t nil "--system-site-packages" "--quiet" "/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block")
============== Function call-process returned 0
Making virtualenv at /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block (SYNC)...Done
============ Function python-environment--blocking-process returned nil
============ Function python-environment--blocking-process called with args ("Running: pip install --upgrade /Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/" ("/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/pip" "install" "--upgrade" "/Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/"))
Running: pip install --upgrade /Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/ (SYNC)...
============== Function call-process called with args ("/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/pip" nil t nil "install" "--upgrade" "/Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/")
============== Function call-process returned 0
Running: pip install --upgrade /Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/ (SYNC)...Done
============ Function python-environment--blocking-process returned nil
========== Function python-environment-run-block returned nil
======== Function jedi:install-server-block returned nil

@immerrr
Copy link
Collaborator

immerrr commented May 4, 2020

No problem, thanks a lot. This gives a lot of information.

The venv is created via the following command:

"virtualenv" "--system-site-packages" "--quiet" "/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block"

And then jedi is installed with

"/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/pip" "install" "--upgrade" "/Users/jose.junior/.emacs.d/elpa/jedi-core-20191011.1750/"

Could you please try the following:

  • remove the /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block directory
  • re-create the virtualenv with the abovemention virtualenv ... command
  • install jedi into that virtualenv with pip ... command
  • verify that /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/jediepcserver still has the incorrect shebang, #!/usr/local/opt/python/bin/python3.7
  • see if /Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/pip has the same incorrect shebang

If pip has the same incorrect shebang, could you then do:

  • remove the virtualenv directory again
  • and re-create it with
"virtualenv" "--quiet" "/Users/jose.junior/.emacs.d/.python-environments/jedi-trace-install-server-block"

(same command as before, but without the "--system-site-packages" parameter)

  • see if pip's shebang is fixed after that

@andyqhan
Copy link

andyqhan commented May 25, 2020

Hi, I realize this is an old issue but I'm having the (exact) same problem on my Mac. I've followed the steps you've given and it seems that my /Users/<user>/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/pip has what I think is the correct shebang (#!/Users/<user>/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/python).

My /jediepcserver has the incorrect shebang, in my case #!/usr/local/opt/[email protected]/bin/python3.8.

My case isn't the exact same as OP's, though. I'm using company-jedi, and the incorrect shebang looks slightly different because of python 3.8. I would also like jedi to work in my elpy virtualenv (the thing you get when you do M-x workon).

If it helps, the output of M-x jedi:show-setup-info is:

;; Emacs Lisp version:
(:emacs-version "26.3" :jedi-version "0.2.8" :python-environment-version "0.0.2alpha0")
;; Python version:
nil
;; EPC error:
(:get-epc-error
 (wrong-type-argument epc:manager nil))
;; Command line:
; (this is set to my own virtualenv folder because of an earlier troubleshooting attempt; it didn't work)
(:virtualenv "/Users/<user>/.local/bin/virtualenv" :virtualenv-version "virtualenv 20.0.20 from /Users/<user>/.local/pipx/venvs/virtualenv/lib/python3.8/site-packages/virtualenv/__init__.py\n")
;; Customization:
((jedi:complete-on-dot . t)
 (jedi:doc-display-buffer . display-buffer)
 (jedi:doc-hook view-mode)
 (jedi:doc-mode . rst-mode)
 (jedi:environment-root)
 (jedi:environment-virtualenv)
 (jedi:get-in-function-call-delay . 1000)
 (jedi:get-in-function-call-timeout . 3000)
 (jedi:goto-definition-config
  (nil nil nil)
  (t nil nil)
  (nil definition nil)
  (t definition nil)
  (nil nil t)
  (t nil t)
  (nil definition t)
  (t definition t))
 (jedi:goto-definition-hook)
 (jedi:goto-definition-marker-ring-length . 16)
 (jedi:imenu-create-index-function . jedi:create-nested-imenu-index)
 (jedi:import-python-el-settings . t)
 (jedi:install-imenu)
 (jedi:install-python-jedi-dev-command "pip" "install" "--upgrade" "git+https://github.com/davidhalter/jedi.git@master#egg=jedi")
 (jedi:key-complete .
                    [C-tab])
 (jedi:key-goto-definition .
                           [67108910])
 (jedi:key-goto-definition-pop-marker .
                                      [67108908])
 (jedi:key-related-names . "�r")
 (jedi:key-show-doc . "�d")
 (jedi:server-args)
 (jedi:server-command "/Users/<user>/.emacs.d/.python-environments/jedi-trace-install-server-block/bin/jediepcserver")
 (jedi:setup-keys)
 (jedi:tooltip-method pos-tip popup)
 (jedi:use-shortcuts)
 (python-environment-default-root-name . "default")
 (python-environment-directory . "~/.emacs.d/.python-environments")
 (python-environment-virtualenv "virtualenv" "--system-site-packages" "--quiet"))

@immerrr
Copy link
Collaborator

immerrr commented Jun 7, 2020

@ibynx thank you for shedding some more light. So... to summarize the issue as I see it:

  1. you create a venv with virtualenv command:
"virtualenv" "--quiet" "/path/to/venv"
  1. pip script inside that virtualenv has the correct shebang
  2. you install jedi with that pip script
"/path/to/venv/bin/pip" "install" "--upgrade" "$(find ~/.emacs.d/elpa -type d -name jedi-core-* | sort | tail -n1)"
  1. /path/to/venv/bin/jediepcserver ends up with an incorrect shebang that references global python interpreter

Looks like an issue between virtualenv and pip, but let's troubleshoot this more. Next questions:

@deddu
Copy link

deddu commented Jun 11, 2020

same issue as @ibynx and identical jedi:show-setup-info. I've installed python3 via homebrew, pip 20.1.1, virtualenv 20.0.21. Should be the latest one, afaict.

@immerrr
Copy link
Collaborator

immerrr commented Jun 15, 2020

Do virtualenv and pip produce the same incorrect shebang if you run those commands outside of Emacs?

"virtualenv" "--quiet" "/path/to/venv"

and

"/path/to/venv/bin/pip" "install" "--upgrade" "$(find ~/.emacs.d/elpa -type d -name jedi-core-* | sort | tail -n1)"

If yes, this is a bug that needs to be reported to pip project. I can add a workaround to jedi-core for now, but if it's a bug in a different project, it has to be solved there.

@raghavkarol
Copy link

Getting the same problem with python3.8 where the shebang is incorrect. It seems like a in issue in lisp code that installs jedi, doing the same by hand gives me the correct shebang.

Doing a M-x jedi:install-server and then

➜  .python-environments git:(master) ✗ pwd
/Users/rkarol-admin/.emacs.d/.python-environments
➜  .python-environments git:(master) ✗ (head default/bin/jediepcserver )
#!/usr/local/opt/[email protected]/bin/python3.8 <--- INCORRECT
# -*- coding: utf-8 -*-
import re
import sys
from jediepcserver import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())
➜  .python-environments git:(master) ✗

Installing manually using pip

 ➜  (rm -rf default ; virtualenv default ; default/bin/pip install /Users/rkarol-admin/.emacs.d/elpa/jedi-core-20191011.1750 && head default/bin/jediepcserver )             

created virtual environment CPython3.8.6.final.0-64 in 211ms
  creator CPython3Posix(dest=/Users/rkarol-admin/github/raghavkarol/dotfiles/emacs.d/.python-environments/default, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/rkarol-admin/Library/Application Support/virtualenv)
    added seed packages: pip==20.2.3, setuptools==50.3.1, wheel==0.35.1
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
Processing /Users/rkarol-admin/.emacs.d/elpa/jedi-core-20191011.1750
Collecting jedi>=0.11.0
  Using cached jedi-0.17.2-py2.py3-none-any.whl (1.4 MB)
Processing /Users/rkarol-admin/Library/Caches/pip/wheels/35/6c/bb/1a71c8fc3843b5dff303fb55edfd21edcfc91493818ebef783/epc-0.0.5-py3-none-any.whl
Collecting argparse
  Using cached argparse-1.4.0-py2.py3-none-any.whl (23 kB)
Collecting parso<0.8.0,>=0.7.0
  Using cached parso-0.7.1-py2.py3-none-any.whl (109 kB)
Processing /Users/rkarol-admin/Library/Caches/pip/wheels/a4/56/32/33b8d1078075cf1aad54c12b9b04de4117c3dd22fc539730df/sexpdata-0.0.3-py3-none-any.whl
Building wheels for collected packages: jediepcserver
  Building wheel for jediepcserver (setup.py) ... done
  Created wheel for jediepcserver: filename=jediepcserver-0.2.8-py3-none-any.whl size=6456 sha256=60a08f2821677c67731ccc3eeb8427a2ae411a04a7b526d13a060503ed56b72b
  Stored in directory: /Users/rkarol-admin/Library/Caches/pip/wheels/5d/23/e2/0c7c709a97b9e68ca3cc9357d33dea12029fe7d5689fed2b4e
Successfully built jediepcserver
Installing collected packages: parso, jedi, sexpdata, epc, argparse, jediepcserver
Successfully installed argparse-1.4.0 epc-0.0.5 jedi-0.17.2 jediepcserver-0.2.8 parso-0.7.1 sexpdata-0.0.3
WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
You should consider upgrading via the '/Users/rkarol-admin/github/raghavkarol/dotfiles/emacs.d/.python-environments/default/bin/python -m pip install --upgrade pip' command.
#!/Users/rkarol-admin/github/raghavkarol/dotfiles/emacs.d/.python-environments/default/bin/python <--- CORRECT
# -*- coding: utf-8 -*-
import re
import sys
from jediepcserver import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

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

No branches or pull requests

5 participants