How do I use this with a virtual env?
from https://vxlabs.com/2018/06/08/python-language-server-with-emacs-and-lsp-mode/
```
Install the python-language-server into the virtual environment, or user environment, that you鈥檙e planning to use.
These days, I tend to use pipenv:
cd my_project
pipenv install python-language-server[all]
...
Importantly, use pyvenv or something similar to switch to the relevant virtualenv before opening the first Python file.```
Just want to point out that those of us using, for instance, the macOS native compiled Emacs, face particular challenges setting the environment that spawns the Emacs process. Apple makes it really difficult to set env vars for *.apps. The OS prevents us from having multiple processes open simultaneously for the same .app, so simply spawning a new shell session with a different virtualenv activated doesn't work either.
The inability to easily customize the pyls command path on a per-project basis has made lsp-mode for lsp-python unusable for me.
I haven't gotten around to patching this on my own box. This other issue I have open can be extended: https://github.com/emacs-lsp/lsp-mode/issues/397
I'd rather get consensus re: design before moving on it. IMO, stdio should interactively prompt for the shell command to use, with a pre-populated default that is overridable with a custom var.
@alyssackwan I don't know what's your specific case but I have been using emacs on mac os with lsp for python development for while now. It's not perfect but is working pretty stable for while. You can take a look at my settings to see the changes that I had to do to make it work!
Good luck!
Answered in https://github.com/emacs-lsp/lsp-mode/issues/393#issuecomment-404949030 .
The comment gregnwosu provided is out of date, since it use lsp-define-stdio-client and it is depreciated, for now you might use something like this to register a new client, but it does not work very well with virtualenv or pyvenv, then I finally make it work by written a small bash script like this:
#!/bin/bash
PYLS=`pwd`/venv/bin/pyls
$PYLS $@
since I put all my venv files under project root, and name that folder with venv, so this trick works for now, hope this may help someone who googled and end up here.
Most helpful comment
Just want to point out that those of us using, for instance, the macOS native compiled Emacs, face particular challenges setting the environment that spawns the Emacs process. Apple makes it really difficult to set env vars for
*.apps. The OS prevents us from having multiple processes open simultaneously for the same.app, so simply spawning a new shell session with a different virtualenv activated doesn't work either.The inability to easily customize the
pylscommand path on a per-project basis has madelsp-modeforlsp-pythonunusable for me.I haven't gotten around to patching this on my own box. This other issue I have open can be extended: https://github.com/emacs-lsp/lsp-mode/issues/397
I'd rather get consensus re: design before moving on it. IMO, stdio should interactively prompt for the shell command to use, with a pre-populated default that is overridable with a custom var.