What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install

When I was building the development environment for django, I was addicted to the following events.

  1. I can't jump to the django module installed by pip install
  2. Importing my own module causes an error and quick fix is ​​invalid

スクリーンショット 2021-01-02 16.45.08.png

It's my environment.

The code works even if there is an error, but if the quick fix does not work, the work efficiency will drop and the error will be unpleasant. I want to erase it.

As a result of investigation, it was because VS Code could not find the target module. The error can be resolved by adding the search path of the target module to the setting item of Pylance.

Add python.analysis.extraPaths to settings.json

1. Open the VS Code configuration file (settings.json)

If you press shift + cmd + P and search for" settings ", it will be suggested.

スクリーンショット 2021-01-02 15.47.14.png

2. Add the module search path to settings.json

Add _ ** python.analysis.extraPaths ** _ and describe the full path of the module to be searched.

settings.json


    "python.analysis.extraPaths": [
       
        //Django library storage directory
        "/Users/user_name/.pyenv/versions/3.9.0/lib/python3.9/site-packages",        
        //Project root directory
        "/Users/user_name/workspace/project_name",
    ],

The error has been resolved and code jumps and quick fixes are now enabled. スクリーンショット 2021-01-02 16.43.36.png

Recommended Posts

What to do if an error occurs in VS Code when importing a django module or your own module installed by pip install
What to do and how to install when an error occurs in DXRuby 1.4.7
What to do if an error occurs when doing npm install axios in React + Typescript project
What to do if you get an error with bundle install by entering gem'bcrypt' in your Gemfile
What to do if you get a "302" error in your controller unit test code in Rails
What to do when an UnsupportedCharsetException occurs in a lightweight JRE
What to do when a null byte error occurs
What to do if an ActionController :: UnknownFormat error occurs
What to do if mysql2 gets a bundle install error
What to do if you get an error in Basic authentication during Rails test code
What to do if you get a gcc error in Docker
What to do if you get a DISPLAY error in gym.render ()
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do when a javax.el.PropertyNotWritableException occurs
Add gem'rails-i18n','~> 6.0.0' and what to do if bundle install gives an error
no space left on device What to do if an error occurs
What to do if you get an error when you hit Heroku logs
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do if you should have installed Rails but an error occurs with rails -v (for beginners)
What to do if you get an error saying Cannot find a valid baseurl for repo when you use yum -y install docker in a udemy course using CentOS7
What to do if you get an "A server is already running." Error when you try to start the rails server
wildflly10 java8 ERROR [org.jboss.jca.core.tx.jbossts.XAResourceRecoveryImpl] (Periodic Recovery) IJ000906 What to do if an error occurs
What to do when IllegalStateException occurs in PlayFramework
What to do if ffi installation fails when launching an application in Rails
What to do if you get an Argument Error: wrong number of arguments (given 2, expected 0) in your RSpec test
What to do if you get an error saying "Please enter a valid value" when getting with Rails datetime_field
What to do if you get an error saying "Could not find a JavaScript runtime." When starting rails server
What to do if you get a wrong number of arguments error in binding.pry
What to do if you get a port error when docker-compose up on Mac
What to do if ClassNotFoundException occurs when starting Tomcat
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
What to do when an error occurs in rails db: migrate ((StandardError: An error has occurred, this and all later migrations canceled :))
<Dot installation> What to do if you cannot proceed due to an error when building a development environment for Rails learning.
What to do if you don't see the test code error message in the terminal console
[Rails] What to do if you accidentally install bundle in the production environment in your local environment
What to do if you get a "Cannot Pull Container Error" when starting ECS ​​Fargate
[Rails 6] What to do when a missing a template error occurs after introducing haml [Super easy]
What to do if you get a java.io.IOException in GlassFish
An error occurs when codedeploy-agent is installed in Ubuntu Server 20.04
[Programming beginner] What to do when rails s becomes an error in the local development environment
[Ruby] What to do when the error "cannot load such file" appears when executing VS Code debug
What to do if you get a "Mysql2 :: Error: Operand should contain 1 column (s)" error in Rails
What to do if an SSH key authentication error occurs during automatic deployment to EC2 with Capistrano
What to do if you get an [An HTTP request took too long to complete.] Error in Docker.
What to do if zip dies if there is a pom when making an executable jar with gradle
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do when javax.batch.operations.JobStartException occurs
What to do if you get a groovy warning in Thymeleaf Layout
What to do if you get an error during rails db: reset
What to do if you get an uninitialized constant Likes Controller error
What to do if you don't like the code generated by swagger-codegen-cli
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if you get the error message "Don't try to install it manually: your package manager does it automatically. However, a different version of webpack was detected higher up in the tree:" when you do "npm start" Law
What to do if the build fails with the error "Module compiled with Swift x.x.x cannot be imported by the Swift x.x.x compiler"
What to do if you get Could not save master table to file after importing a project in Eclipse
A reminder when an aapt.exe error occurs
What to do if you install Ubuntu
What to do if you get a SQLite3 :: BusyException: database is locked error
I get an error when I try to use "^" or "$" in ruby ​​regular expression
What to do if you get an error on heroku rake db: migrate
Error 400 occurs when executing Query by specifying Japanese as a condition in SOQL