Skip to content

[Question] Virtual environments? #29

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

Closed
TitaniumHocker opened this issue May 6, 2021 · 12 comments
Closed

[Question] Virtual environments? #29

TitaniumHocker opened this issue May 6, 2021 · 12 comments

Comments

@TitaniumHocker
Copy link

Hello!

First of all thank you guys for supporting this fork.

I'm using neovim as my main code editor and right now I'm trying to migrate from coc.nvim to native neovim LSP client implementation(which is still in development btw).

So, I don't figured out how to configure this language server to use executables from virtual environment instead of global scope of my system. For example from python venv or pipenv. In coc It was enough just to specify configuration parameter "python.pythonPath" with the full path to the python executable file in the virtual environment and everything works fine.

Tech information above
System: Manjaro GNU/Linux
LSP Client: neovim v0.5.0-dev

@yeraydiazdiaz
Copy link
Contributor

yeraydiazdiaz commented May 14, 2021

I wondered about this too, maybe I'm missing something but using Sublime Text I specify the pylsp executable which starts the server in its own virtual environment. Plugins, built-in and external, import the libraries and from that virtual environment and returns responses, however, the versions of these libraries may be different than those of the project I am working on (with the exception of pyls-flake8 which invokes a subprocess).

To be fair this is generally not a problem for most plugins since they don't change that much between versions anyway, but in other editors like PyCharm or VSCode you'll be prompted to install the missing library in your virtual environment.

Am I correct in that interpretation? Is this a problem in the design of pylsp or something that could be solved at the plugin level?

@yaegassy
Copy link
Contributor

yaegassy commented May 17, 2021

I used "coc.nvim" to create coc-pylsp for "verification". https://github.com/yaegassy/coc-pylsp

It is only for verification, so it is not published on npm.

Why not just detect the pylsp command and invoke it without determining whether it is a global or virtual environment?

If you want to use pylsp and more tools, any version at the project level, I guess the approach would be to install pylsp in a virtual environment.

@TitaniumHocker
Copy link
Author

I can run nvim from venv shell and the language server will work file, but only if language server and pynvim is installed in this venv. Installing this packets for every project venv seems wasteful to me.

@yaegassy
Copy link
Contributor

I have pynvim installed on a system global basis. However, I think it works fine in "venv". I don't think running a language server has anything to do with pynvim, but if I'm wrong, I'm sorry.

@TitaniumHocker
Copy link
Author

I have an error if pynvim is not installed in venv:

No "python3" provider found. Run ":checkhealth provider"

May be it's only in my configuration.

@yaegassy
Copy link
Contributor

This is an excerpt in my environment. No problem.

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "/usr/local/bin/python3"
  - INFO: Executable: /usr/local/bin/python3
  - INFO: Python version: 3.9.5
  - INFO: pynvim version: 0.4.3
  - OK: Latest pynvim is installed.

## Python virtualenv
  - INFO: $VIRTUAL_ENV is set to: /private/tmp/venvcheck/venv
  - INFO: Python version: 3.9.5
  - OK: $VIRTUAL_ENV provides :!python.

The pynvim thing has nothing to do with pylsp, so you can ask about it on Neovim's "gitter" or "issue".

@TitaniumHocker
Copy link
Author

I worked some days with using separate lsp server to each venv, works fine. So, I'll close the issue. Thanks for help.

@weeman1337
Copy link

Hi @TitaniumHocker so you are installing python-lsp-server in every project? To me that looks like a huge overhead. Did anybody find out how to install python-lsp-server globally or in a separate virtualenv and point it to the project currently working on?

@meshy
Copy link

meshy commented Jul 18, 2021

Neovim 0.5 is out now, so this is no longer just for pre-release. Installing pylsp in the venv feels like a hack, and is a frustrating
step to have to repeat after rebuilding venvs.

Thankfully I'm not using a stricter python package manager that would object to the extra package.

I am still looking for a solution to this that makes it work more like my previous setup in neovim.

@ccordoba12
Copy link
Member

We provide the option pylsp.plugins.jedi.environment to configure your preferred environment, so you need to make use of it (see our configuration description file).

Note: This is something that needs to be solved client-side, so please stop posting comments here and open an issue in Neovim or your other editors or IDEs to add support for that.

@meshy
Copy link

meshy commented Jul 19, 2021

Apologies for the noise. Thanks for the pointer.

@apapsch
Copy link

apapsch commented Aug 11, 2023

My global pylsp script:

#!/bin/sh
pipenv scripts > /dev/null 2>&1 || {
    echo "run pylsp inside directory with Pipfile"
    exit 1
}
exec pipenv run pylsp "$@"

Please mind the hack. 🚂

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

7 participants