Giter Club home page Giter Club logo

Comments (34)

ztlevi avatar ztlevi commented on June 14, 2024 5

@qrebjock Try pipenv instead of anaconda. Anaconda seems evil to me cuz I realized it's super unfriendly and hacky to install packages. pipenv works for me and ivanknmk with pipenv.

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024 3

@seagle0128 I have summarized the issues I encountered using conda with pyright in this test repo https://github.com/ztlevi/python-test2

Could you take a look at it? Thanks

  • pyright version: 1.1.65
  • lsp-pyright version: 9603dda
  • lsp-mode: 4145a70ce1d4bfb2463606ba34c5965080b080d9
  • emacs: 27.1

from lsp-pyright.

Ivanknmk avatar Ivanknmk commented on June 14, 2024 3

@tshu-w @seagle0128 I found using prightconfig.json with pipenv environment works. There might be some bugs for conda. You need to activate the pipenv env and do lsp-restart-workspace.

This was actually EXTREMELY helpful. Thank you very much!

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024 1

The venvPath is taking effect. If I use lsp-register-custom-settings, it shows

The venvPath has been specified in both the config file and the VS Code settings. The value in the config file (/Users/ztlevi/.conda/envs/test/bin/python3) will take precedence

I'm thinking maybe I need to set pythonPath. But no luck get it working

from lsp-pyright.

lyjdwh avatar lyjdwh commented on June 14, 2024 1

I also find that setting "stubPath": "/xxx/xxx/.conda/envs/xxx/lib/xxx/site-packages" in pyrightconfig.json works!

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024 1

@seagle0128 Thanks. That's working.

BTW, why is setting in pyrightconfig.json file not working?

{
  "venvPath": "/Users/ztlevi/.conda/envs/test/",
  "pythonPath": "/Users/ztlevi/.conda/envs/test/bin/python3"
}

from lsp-pyright.

wztdream avatar wztdream commented on June 14, 2024 1

I use spacemacs and I found conda layer works like a charm:

  1. install conda layer
  2. add python-mode hook to activate the conda env you like, for example
   (add-hook 'python-mode-hook
            (lambda ()
            (conda-env-activate "pytorch")))

Above code will activate pytorch env if you open python files.

from lsp-pyright.

50ways2sayhard avatar 50ways2sayhard commented on June 14, 2024

assign a default value to python.venvPath may solve this problem.
like this:

(lsp-resgister-custom-settings
 `(("python.venvPath" ""))
)

from lsp-pyright.

seagle0128 avatar seagle0128 commented on June 14, 2024

Can we set both pythonPath and venvPath ? Like this?

("python.pythonPath" lsp-pyright-locate-python)
("python.venvPath" lsp-pyright-venv)

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

@seagle0128 How can I use it? There is no lsp-pyright-locate-venv function.

I tried

  (lsp-register-custom-settings
   '("python.pythonPath" lsp-pyright-locate-python))
  (lsp-register-custom-settings
   `("python.pythonPath" ,(lsp-pyright-locate-python)))

Both gives me errors

from lsp-pyright.

seagle0128 avatar seagle0128 commented on June 14, 2024

@ztlevi This should be fine. lsp-pyright-locate-venv has not been implemented.

(lsp-register-custom-settings
   `("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python"
      "python.venvPath" "/Users/ztlevi/.conda/envs/test"))

from lsp-pyright.

zeronone avatar zeronone commented on June 14, 2024

I think the problem here is that Python interpreter is incorrectly selected as the system python interpreter. Can you open emacs after activating the conda env?

Regarding numpy it will probably not work very well without type-stubs. Pyright heavily depends on the availability of type-stubs. https://github.com/microsoft/pyright/blob/master/docs/import-resolution.md

I think venvPath is very confusing. If I am not wrong, just adding venvPath does nothing; it should be used in conjunction with executionEnvironment. Since executionEnvironment is configured in pyrightconfig.json, it is better to configure venvPath there too (rather than configuring through emacs).
See here for example: https://github.com/microsoft/pyright/blob/master/docs/configuration.md

from lsp-pyright.

50ways2sayhard avatar 50ways2sayhard commented on June 14, 2024

There is a TypeError Error reading settings: TypeError: Cannot read property 'replace' of undefined if no venvPath in settings, and Pyright will not search packages in venvPath configured in pyrightconfig.json.
image
image

from lsp-pyright.

lyjdwh avatar lyjdwh commented on June 14, 2024

When I set python.venvPath python.pythonPath through lsp-register-custom-settings, the TypeError Error reading settings: TypeError: Cannot read property 'replace' of undefined disappears, but autocompletion is still not working.

from lsp-pyright.

zeronone avatar zeronone commented on June 14, 2024

In my experience the TypeError should be harmless.

Can you try the following from the root of your project.

pyright --createstub pandas

It will create a typings directory in your root, it might help a little bit with the completion.

from lsp-pyright.

lyjdwh avatar lyjdwh commented on June 14, 2024

Yes , pyright --createstub pandas helps.

from lsp-pyright.

seagle0128 avatar seagle0128 commented on June 14, 2024

@zeronone maybe PR #9 is helpful. Please review.

from lsp-pyright.

zeronone avatar zeronone commented on June 14, 2024

Basically, lsp-pyright doesn't perform well if there are no type stubs (microsoft/pyright#556); also current completion problem is not related to venvPath (venvPath is useful when you have multiple sub projects each with different virtualenv; and the names of each venv should be specified in pyrightconfig.json. Even if you specify venvPath, you still need to specify executionEnvironment[].venv for each sub-project).


@seagle0128 Thanks a lot, I left some comments.

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

@ztlevi This should be fine. lsp-pyright-locate-venv has not been implemented.

(lsp-register-custom-settings
   `("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python"
      "python.venvPath" "/Users/ztlevi/.conda/envs/test"))

I got this error with your code

Debugger entered--Lisp error: (wrong-type-argument listp "/Users/ztlevi/.conda/envs/test/bin/python")
  lsp--compare-setting-path("/Users/ztlevi/.conda/envs/test/bin/python" "python.pythonPath")
  -contains\?(("python.pythonPath") "/Users/ztlevi/.conda/envs/test/bin/python")
  -uniq(("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python" "python.venvPath" "/Users/ztlevi/.conda/envs/test" ("pyright.disableLanguageServices" lsp-pyright-disable-language-services) ("pyright.disableOrganizeImports" lsp-pyright-disable-organize-imports) ("python.analysis.useLibraryCodeForTypes" lsp-pyright-use-library-code-for-types) ("python.analysis.diagnosticMode" lsp-pyright-diagnostic-mode) ("python.analysis.typeCheckingMode" lsp-pyright-typechecking-mode) ("python.analysis.logLevel" lsp-pyright-log-level) ("python.analysis.autoSearchPaths" lsp-pyright-auto-search-paths) ("python.analysis.extraPaths" lsp-pyright-extra-paths) ("python.pythonPath" lsp-pyright-locate-python) ("rfLanguageServer.trace.server" lsp-rf-language-server-trace-server) ("rfLanguageServer.logLevel" lsp-rf-language-server-log-level) ("rfLanguageServer.libraries" lsp-rf-language-server-libraries) ("rfLanguageServer.excludePaths" lsp-rf-language-server-exclude-paths) ("rfLanguageServer.includePaths" lsp-rf-language-server-include-paths) ("kotlin.externalSources.autoConvertToKotlin" lsp-kotlin-external-sources-auto-convert-to-kotlin t) ("kotlin.externalSources.useKlsScheme" lsp-kotlin-external-sources-use-kls-scheme t) ("kotlin.debugAdapter.path" lsp-kotlin-debug-adapter-path) ("kotlin.debugAdapter.enabled" lsp-kotlin-debug-adapter-enabled t) ("kotlin.completion.snippets.enabled" lsp-kotlin-completion-snippets-enabled t) ("kotlin.linting.debounceTime" lsp-kotlin-linting-debounce-time) ("kotlin.compiler.jvm.target" lsp-kotlin-compiler-jvm-target) ("kotlin.trace.server" lsp-kotlin-trace-server) ("kotlin.languageServer.path" lsp-clients-kotlin-server-executable) ("ada.projectFile" lsp-ada-project-file) ("ada.enableDiagnostics" lsp-ada-enable-diagnostics) ("ada.defaultCharset" lsp-ada-option-charset) ("java.codeGeneration.toString.limitElements" lsp-java-code-generation-to-string-limit-elements) ("java.codeGeneration.toString.listArrayContents" lsp-java-code-generation-to-string-list-array-contents t) ("java.codeGeneration.toString.skipNullValues" lsp-java-code-generation-to-string-skip-null-values t) ("java.codeGeneration.toString.codeStyle" lsp-java-code-generation-to-string-code-style) ("java.codeGeneration.toString.template" lsp-java-code-generation-to-string-template) ("java.codeGeneration.generateComments" lsp-java-code-generation-generate-comments t) ("java.codeGeneration.useBlocks" lsp-java-code-generation-use-blocks t) ("java.codeGeneration.hashCodeEquals.useInstanceof" lsp-java-code-generation-hash-code-equals-use-instanceof t) ("java.codeGeneration.hashCodeEquals.useJava7Objects" lsp-java-code-generation-hash-code-equals-use-java7objects t) ("java.format.onType.enabled" lsp-java-format-on-type-enabled t) ("java.format.comments.enabled" lsp-java-format-comments-enabled t) ("java.format.settings.profile" lsp-java-format-settings-profile) ("java.format.settings.url" lsp-java-format-settings-url) ("java.progressReports.enabled" lsp-java-progress-reports-enabled t) ("java.foldingRange.enabled" lsp-java-folding-range-enabled t) ("java.completion.importOrder" lsp-java-completion-import-order) ("java.completion.favoriteStaticMembers" lsp-java-completion-favorite-static-members) ("java.completion.guessMethodArguments" lsp-java-completion-guess-method-arguments t) ("java.completion.overwrite" lsp-java-completion-overwrite t) ("java.completion.enabled" lsp-java-completion-enabled t) ...))
  lsp-register-custom-settings(("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python" "python.venvPath" "/Users/ztlevi/.conda/envs/test"))
  (progn (lsp-register-custom-settings (quote ("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python" "python.venvPath" "/Users/ztlevi/.conda/envs/test"))))
  eval((progn (lsp-register-custom-settings (quote ("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python" "python.venvPath" "/Users/ztlevi/.conda/envs/test")))) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

from lsp-pyright.

seagle0128 avatar seagle0128 commented on June 14, 2024

@ztlevi typo. should be

(lsp-register-custom-settings
   `(("python.pythonPath" "/Users/ztlevi/.conda/envs/test/bin/python")
      ("python.venvPath" "/Users/ztlevi/.conda/envs/test")))

from lsp-pyright.

lyjdwh avatar lyjdwh commented on June 14, 2024

After setting python.pythonPath python.venvPath through lsp-register-custom-settings , the third-party completion still doesn't work. Do you set any other thing? @ztlevi

from lsp-pyright.

failable avatar failable commented on June 14, 2024

@ztlevi May I ask how to make lsp-register-custom-settings work for multiple envs for different projects?

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

@Isolet You could put lsp-register-custom-settings in .dir-locals.el file

((python-mode  
  (eval . (lsp-register-custom-settings ...)))

But it would be ideal to put configs in pyrightconfig.yaml

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

@Isolet Yeah, auto completion doesn't work but jump to definition works on my end

from lsp-pyright.

failable avatar failable commented on June 14, 2024

@ztlevi Thanks. Have you got completion and documentation work now?

from lsp-pyright.

zeronone avatar zeronone commented on June 14, 2024

Regarding numpy completions, I found a bug in our implementation. Could you try #12 and see if it fixes the issue for you.

from lsp-pyright.

tshu-w avatar tshu-w commented on June 14, 2024

setting pyrightconfig.json not work on my side either. @seagle0128

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

@tshu-w @seagle0128 I found using prightconfig.json with pipenv environment works. There might be some bugs for conda. You need to activate the pipenv env and do lsp-restart-workspace.

from lsp-pyright.

qrebjock avatar qrebjock commented on June 14, 2024

Hello all,

I am also trying to use Emacs (spacemacs) with lsp and conda. Without any configuration it uses the system python 2.7 located in /usr/bin/python.

Adding the code

  (with-eval-after-load 'lsp-mode
    (lsp-register-custom-settings
     '(("python.pythonPath" "~/miniconda3/bin/python")
       ("python.venvPath" "~/miniconda3")))
    )

doesn't work.
Creating a config file like https://github.com/ztlevi/python-test2/blob/master/pyrightconfig.json neither.
What I can do is open a file and then change to a conda env and reload lsp workspace.

I was wondering if you had found some fix for this?

from lsp-pyright.

tshu-w avatar tshu-w commented on June 14, 2024

@qrebjock I'm not really sure, but I think that if you want to use conda python, the path of conda python should be in front of other python paths in your system variable PATH and make sure emacs load your system variables correctly. As for spacemacs, you can refer here.

You can check it by M-: (executable-find "python")

After that, If you want to use conda other envs, you can make a .dir-locals.el in your project file like this:

;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((python-mode . ((eval . (lsp-register-custom-settings
                          '(("python.pythonPath" "/home/wts/.anaconda3/envs/iswc/bin/python"
                             "python.venvPath" "/home/wts/.anaconda3/envs/iswc")))))))

from lsp-pyright.

qrebjock avatar qrebjock commented on June 14, 2024

Thanks for your answers.

@ztlevi I also have some problems with conda but I would rather keep using it because it makes things easy and smooth in many other cases.

@tshu-w Thanks for the tips, it has been helpful. I made sure that conda python appears in front of everything in my PATH. I think this works because when I send a file to the REPL it finds the correct version of python.
Regarding the file .dir-locals.el you mentioned it seems to be helpful. But I have to restart the LSP workspace for it to take effect. I guess the file is loaded after LSP.
Here is the LSP log I get before reloading:

Command "/usr/local/bin/pyright-langserver --stdio" is present on the path.
Command "pyls" is present on the path.
Command "/usr/local/bin/pyright-langserver --stdio" is present on the path.
Command "pyls" is present on the path.
Found the following clients for /Users/quentinrebjock/Documents/fanok/fanok/sdp/sdp.py: (server-id pyright, priority 3), (server-id pyls, priority -1)
The following clients were selected based on priority: (server-id pyright, priority 3)
Pyright language server 1.1.96 starting
Server root directory: /usr/local/lib/node_modules/pyright/dist/
This server does not support foldingRangeProvider
Creating watch for /Users/quentinrebjock/test
Cancelling textDocument/codeAction(3) in hook post-command-hook
No configuration file found.
Setting pythonPath for service "fanok": "/usr/bin/python"
stubPath /Users/quentinrebjock/Documents/fanok/typings is not a valid directory.
Python version 2.7 from interpreter is unsupported
Assuming Python platform Darwin
Searching for source files
Found 32 source files
No configuration file found.
Setting pythonPath for service "numpy": "/usr/bin/python"

And after reloading:

Command "/usr/local/bin/pyright-langserver --stdio" is present on the path.
Command "pyls" is present on the path.
Command "/usr/local/bin/pyright-langserver --stdio" is present on the path.
Command "pyls" is present on the path.
Found the following clients for /Users/quentinrebjock/Documents/fanok/fanok/sdp/sdp.py: (server-id pyright, priority 3), (server-id pyls, priority -1)
The following clients were selected based on priority: (server-id pyright, priority 3)
Cleaning up watches for folder /Users/quentinrebjock/test. There is no workspace watching this folder...
Pyright language server 1.1.96 starting
Server root directory: /usr/local/lib/node_modules/pyright/dist/
This server does not support foldingRangeProvider
Creating watch for /Users/quentinrebjock/Documents/fanok
Creating watch for /Users/quentinrebjock/Documents/fanok/build
Creating watch for /Users/quentinrebjock/Documents/fanok/build/lib.macosx-10.9-x86_64-3.8
Creating watch for /Users/quentinrebjock/Documents/fanok/build/lib.macosx-10.9-x86_64-3.8/fanok
Creating watch for /Users/quentinrebjock/Documents/fanok/build/lib.macosx-10.9-x86_64-3.8/fanok/factor_model
Creating watch for /Users/quentinrebjock/Documents/fanok/build/lib.macosx-10.9-x86_64-3.8/fanok/sdp
Creating watch for /Users/quentinrebjock/Documents/fanok/build/lib.macosx-10.9-x86_64-3.8/fanok/utils
Creating watch for /Users/quentinrebjock/Documents/fanok/build/temp.macosx-10.9-x86_64-3.8
Creating watch for /Users/quentinrebjock/Documents/fanok/build/temp.macosx-10.9-x86_64-3.8/fanok
Creating watch for /Users/quentinrebjock/Documents/fanok/build/temp.macosx-10.9-x86_64-3.8/fanok/factor_model
Creating watch for /Users/quentinrebjock/Documents/fanok/build/temp.macosx-10.9-x86_64-3.8/fanok/sdp
Creating watch for /Users/quentinrebjock/Documents/fanok/build/temp.macosx-10.9-x86_64-3.8/fanok/utils
Creating watch for /Users/quentinrebjock/Documents/fanok/docs
Creating watch for /Users/quentinrebjock/Documents/fanok/docs/source
Creating watch for /Users/quentinrebjock/Documents/fanok/examples
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/factor_model
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/factor_model/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/generation
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/generation/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/sdp
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/sdp/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/statistics
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/statistics/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/utils
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok/utils/__pycache__
Creating watch for /Users/quentinrebjock/Documents/fanok/fanok.egg-info
Creating watch for /Users/quentinrebjock/Documents/fanok/tests
No configuration file found.
Setting pythonPath for service "fanok": "/Users/quentinrebjock/miniconda3/bin/python"
stubPath /Users/quentinrebjock/Documents/fanok/typings is not a valid directory.
Assuming Python version 3.8
Assuming Python platform Darwin
Searching for source files
Found 32 source files
No configuration file found.
Setting pythonPath for service "numpy": "/Users/quentinrebjock/miniconda3/bin/python"
stubPath /Users/quentinrebjock/miniconda3/lib/python3.8/site-packages/numpy/typings is not a valid directory.
Assuming Python version 3.8
Assuming Python platform Darwin
Searching for source files
Found 374 source files
[FG] Long operation: checking: /Users/quentinrebjock/Documents/fanok/fanok/sdp/sdp.py (2753ms)
[FG] Long operation: analyzing: /Users/quentinrebjock/Documents/fanok/fanok/sdp/sdp.py (2936ms)
No configuration file found.
Setting pythonPath for service "fanok_experiments": "/Users/quentinrebjock/miniconda3/bin/python"
stubPath /Users/quentinrebjock/Documents/fanok_experiments/typings is not a valid directory.
Assuming Python version 3.8
Assuming Python platform Darwin
Searching for source files
Found 21 source files
No configuration file found.
Setting pythonPath for service "linalg": "/Users/quentinrebjock/miniconda3/bin/python"
File or directory "/Users/quentinrebjock/test" does not exist.
No source files found.

What I don't get is 1) Why I need to reload and 2) Why do I need this .dir-locals.el file.
I would expect that adding these lines

  (with-eval-after-load 'lsp-mode
    (lsp-register-custom-settings
     '(("python.pythonPath" "~/miniconda3/bin/python")
       ("python.venvPath" "~/miniconda3")))
    )

in my user-config should have the same effect but they don't.

from lsp-pyright.

tshu-w avatar tshu-w commented on June 14, 2024

I think this works because when I send a file to the REPL it finds the correct version of python.

sending a file to the REPL use python-shell--interpreter and there might be some different way to find your python. I still recommend you try M-: (executable-find "python") to check whether this can get your python path correctly as this package uses this to find your python path, see https://github.com/emacs-lsp/lsp-pyright/blob/master/lsp-pyright.el#L160

As for your other questions, the need to reload didn't happen in my configuration (I think there might be some black magic with LSP or spacemacs😂️, I'm not really sure), and .dir-locals.el is for if you want to use conda env (not the base env) in some dir.

from lsp-pyright.

tshu-w avatar tshu-w commented on June 14, 2024

@seagle0128 I have summarized the issues I encountered using conda with pyright in this test repo https://github.com/ztlevi/python-test2

Could you take a look at it? Thanks

  • pyright version: 1.1.65
  • lsp-pyright version: 9603dda
  • lsp-mode: 4145a70ce1d4bfb2463606ba34c5965080b080d9
  • emacs: 27.1

@ztlevi Hi, I tried this test again. Though I got Setting pythonPath for service "python-test2": "/usr/local/anaconda3/bin/python", I got Import "pandas" could not be resolved. So I think pyright is using the correct venv, but the lsp-log shows it incorrectly. Can you tried agained?

from lsp-pyright.

ztlevi avatar ztlevi commented on June 14, 2024

I believe condo did some fancy trick and breaks the paths. The workaround now is to use Pipenv which is more lightweight and natively close to pip.
It shouldn't be a super headache to use pipenv env in emacs and condo env in terminal. I personally use pipenv on laptop with docker based env in remote machine. Having multiple envs works for me

from lsp-pyright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.