coc-python
coc-python copied to clipboard
Wrong Pyright errors.
I get this Pyright errors in neovim which are wrong. It says the import pygame cant be resolved but everything works fine in the code. Is there a way to remove it or is Pyright necessary?I have flake8 as linter, so do I need this pyright. Below is the image of the error:
Please reference this post: https://hanspinckaers.com/fixing-coc-pyright-and-anaconda-import-errors.
The cause of the problem is missing configuration file of pyright in your project root directory.
I am a Django developer. I use pyenv and pyenv-virtualenv manage my virtual env.
I use macOS and my username is alanjui. My home directory is /Users/alanjui/.
I use python 3.8.5 as my default python interpreter:
$ pyenv versions
system
* 2.7.16 (set by /Users/alanjui/.pyenv/version)
3.8.3
* 3.8.5 (set by /Users/alanjui/.pyenv/version)
3.8.5/envs/django-3.8.5
3.8.5/envs/my-dev
3.8.5/envs/my_venv
3.8.5/envs/neovim
django-3.8.5
my-dev
my_venv
neovim
All virtualenv directories are store under ~/.pyenv/versions/3.8.5/envs/ :
$ ll /Users/alanjui/.pyenv/versions/3.8.5/envs
total 0
drwxr-xr-x 8 alanjui staff 256B 10 22 17:55 django-3.8.5
drwxr-xr-x 7 alanjui staff 224B 11 24 15:30 my-dev
drwxr-xr-x 7 alanjui staff 224B 11 11 15:05 my_venv
drwxr-xr-x 7 alanjui staff 224B 11 20 12:37 neovim
I have a project named: 'test-002' and project created under path: ~/workspace/django/. I create a virtualenv named 'test--02' for this project:
(1) Create and enter project directory.
$ cd ~/workspace/django
$ mkdir test-002 && cd $_
(2) Create virtualenv and configure project use 'test-002' as project default virtualenv:
$ pyenv virtualenv 3.8.5 test-002
$ pyenv local test-002
(3) Confirm virtualenv 'test-002' is created:
$ pyenv versions
system
* 2.7.16 (set by /Users/alanjui/.pyenv/version)
3.8.3
* 3.8.5 (set by /Users/alanjui/.pyenv/version)
3.8.5/envs/django-3.8.5
3.8.5/envs/test-002
......
django-3.8.5
test-002
(4) Confirm the virtualenv directory is in the venv paht:
ll /Users/alanjui/.pyenv/versions/3.8.5/envs
total 0
drwxr-xr-x 8 alanjui staff 256B 10 22 17:55 django-3.8.5
......
drwxr-xr-x 7 alanjui staff 224B 11 24 21:32 test-002
(5) Create a configuration file for Pyright and put it the root of project directory. The full path of this pyright configuration file is "~/workspace/django/test-002/pyrightconfig.json".
$ cd ~/workspace/django/test-002
$ touch pyrightconfig.json
$ vim pyrightconfig.json
The content of pyrightconfig.json:
{
"venvPath": "/Users/alanjui/.pyenv/versions/3.8.5/envs",
"venv": "test-002"
}
Be aware do not change the venvPaht to "~/.pyenv/versions/3.8.5/envs" or "$HOME/.pyenv/versions/3.8.5/envs". Otherwise you will got error.