palantir / python-language-server

An implementation of the Language Server Protocol for Python
MIT License
2.6k stars 282 forks source link

how to configure module load path #880

Open brown opened 3 years ago

brown commented 3 years ago

Thanks very much for writing pyls! I'm having a lot of fun using it.

I have installed pyls on my Linux box using "pip install python-language-server". The installed executable shell script is ~/.local/bin/pyls and its first line is "#!/usr/bin/python". That binary is a version 2 Python. I am using the eglot language server client with Emacs, but I don't think my question is specific to the client used. I am working in a Python project directory where ./bin/python3.7 is the right Python interpreter to run. That binary is a shell script that sets up sys.path to contain all the modules that may be loaded by the source code I am editing.

How do I tell pyls to use a specific value of sys.path or alternatively, how do I tell it to query the local ./bin/python3.7 for its sys.path?

brown commented 3 years ago

The python-language-server uses Jedi for completion and code analysis. If you have a Python interpreter that's configured to load all the modules you are interested in, then set the pyls.plugins.jedi.environment parameter to the path of that interpreter. For Emacs with Eglot, you can do that by creating a .dir-locals.el file in the root of your project containing:

((python-mode                                                                                 
  (eglot-workspace-configuration                                                              
   (:pyls                                                                                     
    (:plugins                                                                                 
     (:jedi                                                                                   
      (:environment . "/path/to/python")))))))
brown commented 3 years ago

It would be very helpful for this project to document how all the configuration settings in package.json work.