Skip to content

How do you specify a path to a virtualenv? #660

Closed

Description

@ryankask

I'm trying to migrate my existing emacs setup to use python-language-server via eglot. I am currently using emacs with the emacs-jedi package. I'm able to pass a path to a virtualenv that ends up instantiating a Jedi environment like this: jedienv = jedi.create_environment(venv, safe=safe)

Is there a way to run python-language-server installed in one virtualenv (one that I use for packages requires across projects) but use a different one (ie the project virtualenv) for completion like is done above?

I've read through the existing issues but I'm not sure of the answer (#143, for example). Is it to set VIRTUAL_ENV when running pyls? Is there a way to pass a path instead like described above?

Activity

  1. changed the title [-]How to specify virtualenv path[/-] [+]How do you specify a path to a virtualenv?[/+] on Sep 25, 2019
  2. ccordoba12 commented on Sep 25, 2019

    @ccordoba12
    Contributor

    At the moment there's no way to specify a path to a virtualenv, but we're working on it for a future release.

  3. ryankask commented on Sep 25, 2019

    @ryankask
    Author

    Thanks for the quick response. I'll keep an eye on the repo.

  4. kawing-chiu commented on Nov 12, 2019

    @kawing-chiu

    Hi. Is there an open issue where I can track the progress of this?

  5. ccordoba12 commented on Nov 12, 2019

    @ccordoba12
    Contributor

    See #680.

  6. muffinmad commented on Nov 13, 2019

    @muffinmad
    Contributor

    @ryankask I'm using python-language-server via eglot. The solution is to set VIRTUAL_ENV variable before starting pyls:

    (defvar mad/lsp-venv nil)
    
    (require 'eglot)
    
    (defun mad/eglot-pyls (_interactive)
      (when mad/lsp-venv
        ;; set your path to virtualenvs here
        (setenv "VIRTUAL_ENV" (concat "/Users/mad/.virtualenvs/" mad/lsp-venv)))
      (list "pyls"))
    
    (add-hook 'eglot-server-initialized-hook #'(lambda (_server) (setenv "VIRTUAL_ENV")))
    
    (add-to-list 'eglot-server-programs '(python-mode . mad/eglot-pyls))

    To specify virtualenv I have .dir-locals.el in each project folder:

    ((nil . ((mad/lsp-venv . "envname"))))

    Surely, you can specify virtualenv name in your way, like project directory name or something.

    Jedi is read VIRTUAL_ENV variable: https://github.com/davidhalter/jedi/blob/03920502c42e2d77220cdc5f72fe790e6633ac44/jedi/api/environment.py#L150

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions