[PYTHON] I want to get rid of import warnings from Pyright and pylint in VS Code

This is a solution when you want to switch the environment variable PYTHONPATH for each of multiple folders in the same workspace (but you don't know how to switch).

"Import'xxx' could not be resolved Pyright (report Missing Imports)" warning from Pyright If the warning "Unable to import'xxx' pylint (import-error)" is displayed from pylint, you can change the search folder to be imported for each folder.

Also, even if there are import targets with the same name in multiple folders in the same workspace, proper syntax check and character completion will be effective.

I wanted to easily crush the import warning without dividing the workspace or using the virtual environment with venv, so I searched variously, but I could not find the topic of the same case, so I decided to make a trial and error. , Post as a memorandum.

Folder structure (example)

src/
├── project1/
│   ├── .env (added this)
│   ├── .vscode/
│   │   └── settings.json (added this)
│   ├── project_root/
│   │   └── python_src/
│   │       ├── file1.py
│   │       └── file2.py
│   └── pyrightconfig.json (added this)
├── project2/
│   ├── .env (added this)
│   ├── .vscode/
│   │   └── settings.json (added this)
│   ├── project_root/
│   │   └── python_src/
│   │       ├── file1.py
│   │       └── file2.py
│   └── pyrightconfig.json (added this)
└── server_library/
    └── python_src/
        └── file3.py

Settings for Pyright

Place "pyrightconfig.json" for each folder you want to switch PYTHONPATH directly under the workspace.

src/project1/pyrightconfig.json


{
  "executionEnvironments": [
    {
      "root": "project_root",
      "extraPaths": [
        "project_root/python_src",
        "../server_library/python_src"
      ]
    }
  ]
}

Settings for pylint

json:src/project1/.vscode/settings.json


{
    "python.envFile": "/(Path up to here)/src/project1/.env"
}

src/project1/.env


PYTHONPATH=/(Path up to here)/src/server_library/python_src:/(Path up to here)/src/project1/project_root/python_src

Assumed conditions

Recommended Posts

I want to get rid of import warnings from Pyright and pylint in VS Code
I want to be able to run Python in VS Code
I want to use VS Code and Spyder without anaconda! !! !!
I want to format and check Python code to my liking on VS Code
I want to get League of Legends data ③
I want to get League of Legends data ②
I want to make C ++ code from Python code!
I want to get League of Legends data ①
I want to get / execute variables / functions / classes of external files from Python
I want to get the file name, line number, and function name in Python 3.4
I want to write in Python! (1) Code format check
I want to detect images of cats from Instagram
manage to get rid of heavy pyls in vim-lsp
How to get rid of server custom emoji in message.content
I want to start a lot of processes from python
I want to get the operation information of yahoo route
I want to copy an English paper from pdf and put it in Google Translate
I want to know the features of Python and pip
I want to count unique values in arrays and tuples
I want to map the EDINET code and securities number
Keras I want to get the output of any layer !!
I want to get information from fstab at the ssh connection destination and execute a command
I want you to be aware of what you will develop together from next year. (From "Readable Code")
Get information from the Japan Meteorological Agency and notify Slack of weather warnings in the 23 wards of Tokyo
I get "sanity check" and "No module" errors in import numpy
I want to get the name of the function / method being executed
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
I wrote the code to write the code of Brainf * ck in python
I want to use both key and value of Python iterator
I want to create a pipfile and reflect it in docker
I want to make a parameter list from CloudFormation code (yaml)
Python techniques for those who want to get rid of beginners
I want to know the population of each country in the world.
Migrate from VS Code to PyCharm
Numpy's intellisense (input completion) is incomplete in VS Code and I was lightly addicted to the solution
[Python memo] I want to get a 2-digit hexadecimal number from a decimal number
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I tried to get the authentication code of Qiita API with Python.
I want to sort a list in the order of other lists
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
The file name was bad in Python and I was addicted to import
I want to color a part of an Excel string in Python
I want to analyze the emotions of people who want to meet and tremble
I want to leave an arbitrary command in the command history of Shell
I want to print in a comprehension
How to get rid of long comprehensions
I want to use jar from python
VS Code Pylint is annoying with import! !! !! !!
I want to embed Matplotlib in PySimpleGUI
Get rid of DICOM images in Python
How to make VS Code aware of the venv environment and its benefits
I want to visualize where and how many people are in the factory
I want to get the path of the directory where the running file is stored.
I want to use Python in the environment of pyenv + pipenv on Windows 10
I want to drop a file on tkinter and get its path [Tkinter DnD2]
I want to set a life cycle in the task definition of ECS
I want to see a list of WebDAV files in the Requests module
I want to store the result of% time, %% time, etc. in an object (variable)
I want to connect to PostgreSQL from various languages
I want to do Dunnett's test in Python