Code Monkey home page Code Monkey logo

Comments (2)

ianyepan avatar ianyepan commented on June 18, 2024

To Reproduce

Have pyright 1.1.126 and Python 3.8 installed. Open a Python buffer and attempt to import numpy or matplotlib (previously installed with pip3). See the red underline that reports those imports cannot be resolved.

Example

image

from lsp-pyright.

ianyepan avatar ianyepan commented on June 18, 2024

Solved

From the issue I opened at pyright's repo, the maintainer replied that pyright executes "python3" and runs a small script in the selected Python interpreter to dump the paths the sys.path, and it turns out the command "python3" was exactly the problem! "lsp-pyright" defaults the command to "python", which points to python2 on my system. So after adding the following configuration in my Emacs' setting file init.el, the problem went away:

(setq lsp-pyright-python-executable-cmd "python3")

For fellow Emacs users seeking the answer, the following snippet is the complete solution to have Pyright working in Emacs:

(use-package python
  :config
  (setq python-shell-interpreter "python3"))

(use-package lsp-pyright
  :hook (python-mode . (lambda () (require 'lsp-pyright)))
  :init (when (executable-find "python3")
          (setq lsp-pyright-python-executable-cmd "python3")))

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.