Python

Pylint unresolved import error in Visual Studio Code

19 September 2026 · 8 min read

Pylint unresolved import error in Visual Studio Code

Encountering the dreaded “unresolved import” error in Visual Studio Code while using Pylint can be a frustrating experience for Python developers. This error, often highlighted as a warning in your code editor, signals that Pylint cannot locate a specific module or package that your Python script is attempting to import. This doesn’t necessarily mean the module isn’t installed; rather, it suggests that Pylint’s configuration or environment is not properly set up to recognize it. Addressing this issue is crucial for maintaining code quality and ensuring that your VS Code environment accurately reflects your project’s dependencies. Understanding the common causes and implementing effective solutions will significantly improve your development workflow and prevent unnecessary debugging headaches. We’ll explore various strategies to resolve this Pylint “unresolved import” error in Visual Studio Code, ensuring a smoother Python coding experience.

Understanding the Root Causes of the “Unresolved Import” Error

The Pylint “unresolved import” error in VS Code stems from several potential issues. Primarily, it indicates a mismatch between Pylint’s understanding of your Python environment and the actual location of your modules. This can occur when Pylint is using the wrong Python interpreter, lacks awareness of your virtual environment, or encounters incorrect import paths. Another common cause is related to how VS Code is configured to run Pylint. If the settings are not correctly pointing to the proper Python installation, Pylint won’t be able to resolve the imports, even if they exist.

Furthermore, the structure of your project can contribute to this error. If your project has a complex directory layout or if you’re using relative imports incorrectly, Pylint may struggle to locate the necessary modules. It’s also worth noting that Pylint might not automatically recognize packages installed using certain package managers or custom installation methods. Identifying the specific reason behind the error is the first step towards implementing an effective solution. Properly configuring VS Code and Pylint to align with your project’s environment is key to resolving import issues.

According to the official Pylint documentation, “Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for code smells.” Pylint Documentation. Therefore, ensuring Pylint is correctly configured is vital for its proper functioning. By meticulously checking your VS Code settings, Python interpreter selection, and project structure, you can effectively diagnose and fix the Pylint “unresolved import” error, leading to a cleaner and more efficient coding process.

Configuring Visual Studio Code for Correct Python Interpretation

One of the most common solutions to the Pylint “unresolved import” error involves ensuring that VS Code is using the correct Python interpreter. This is crucial because Pylint relies on the interpreter to locate installed packages. To verify this, open the Command Palette in VS Code (Ctrl+Shift+P or Cmd+Shift+P) and type “Python: Select Interpreter”. Choose the interpreter that corresponds to your project’s virtual environment or the correct Python installation where your packages are installed. Selecting the correct interpreter is a fundamental step in resolving import issues.

After selecting the interpreter, it’s important to verify that VS Code’s Python extension is properly configured to use Pylint with that interpreter. Navigate to your VS Code settings (File > Preferences > Settings) and search for “python.linting.pylintPath”. Ensure that this setting points to the correct Pylint executable associated with your chosen Python interpreter. If Pylint is not installed in the same environment as your interpreter, you may need to install it there or specify the full path to the Pylint executable in the settings.

The following steps can help:

  1. Open the Command Palette (Ctrl+Shift+P or Cmd+Shift+P).
  2. Type “Python: Select Interpreter” and choose the correct interpreter.
  3. Verify the “python.linting.pylintPath” setting in VS Code.

These steps help ensure that VS Code and Pylint are aligned with the correct Python environment, thus resolving the Pylint “unresolved import” error. Remember, a correctly configured environment is the foundation for a smooth Python development experience. Adjusting Pylint Settings and Import Paths

Even with the correct interpreter selected, Pylint might still report “unresolved import” errors if it’s not configured to recognize your project’s specific import paths. This often happens when dealing with custom modules or packages within your project. To address this, you can modify Pylint’s settings to include the necessary directories in its search path. This can be achieved through a Pylint configuration file (.pylintrc or pylint.ini) or directly in VS Code settings.

To configure Pylint using a configuration file, create a .pylintrc file in the root directory of your project. Inside this file, you can specify the --python-path option, which tells Pylint where to look for modules. For example, if your custom modules are located in a directory named “src”, you would add the line python-path=src to the .pylintrc file. Alternatively, you can configure this setting directly in VS Code by adding the following to your settings.json file: "python.linting.pylintArgs": ["--python-path=src"]. Adjusting these settings allows Pylint to correctly resolve imports within your project.

For the featured snippet:

To resolve the Pylint “unresolved import” error, adjust Pylint’s settings to include your project’s import paths. This can be done by creating a .pylintrc file in your project’s root directory and adding the line python-path=your_module_path, replacing your_module_path with the actual path to your modules. This configuration tells Pylint where to look for modules, resolving the import error.

Troubleshooting Common Scenarios and Advanced Configurations

Beyond the basic configurations, several specific scenarios might trigger the Pylint “unresolved import” error. One common issue arises when working with virtual environments. If you’re using a virtual environment, ensure that VS Code is activated within that environment and that Pylint is installed within the same environment. Activating the virtual environment ensures that Pylint uses the correct interpreter and package versions.

Another potential problem is related to relative imports. When using relative imports (e.g., from ..module import something), Pylint might struggle to resolve them if the project structure isn’t properly defined. In such cases, it’s crucial to verify that your project is structured as a package, meaning it contains an __init__.py file in each directory that should be treated as a module. Additionally, consider using absolute imports instead of relative imports for better clarity and maintainability. “Resolving relative import issues” is crucial for larger projects.

Here are some key points to remember:

  • Always activate your virtual environment in VS Code.
  • Verify your project structure, especially when using relative imports.

In complex project setups, you might need to explore advanced Pylint configurations, such as using plugins or custom checkers. These allow you to extend Pylint’s functionality and tailor it to your specific project needs. By understanding these common scenarios and advanced configurations, you can effectively troubleshoot and resolve the Pylint “unresolved import” error, ensuring a seamless coding experience.

Infographic here
FAQ: Addressing Common Questions --------------------------------
Why is Pylint showing "unresolved import" for a module that is definitely installed?
This usually means Pylint is using the wrong Python interpreter or isn't aware of your virtual environment. Make sure VS Code is using the correct interpreter and that Pylint is installed within that environment.
How do I specify the Python path for Pylint?
You can specify the Python path using the `--python-path` option in a `.pylintrc` file or directly in VS Code settings under `python.linting.pylintArgs`.
What if I'm using a virtual environment?
Ensure that your virtual environment is activated in VS Code and that Pylint is installed within that environment.
Remember that consistently checking your configurations and understanding your project structure will save you a lot of debugging time in the long run. By methodically addressing each potential cause, you'll be well-equipped to tackle the **Pylint "unresolved import"** error and maintain a clean, error-free codebase.

Resolving the Pylint “unresolved import” error in Visual Studio Code involves a combination of understanding the error’s root causes and applying the correct configurations. By ensuring that VS Code is using the correct Python interpreter, adjusting Pylint’s settings and import paths, and troubleshooting common scenarios, you can effectively eliminate these errors and improve your coding workflow. Now that you are equipped with the tools and knowledge to tackle this issue, take the time to review your project’s configuration, verify your interpreter settings, and apply the solutions discussed. Don’t hesitate to consult external resources, such as the official Pylint documentation or Stack Overflow Stack Overflow, for further assistance. By proactively addressing these issues, you’ll create a more efficient and enjoyable Python development experience. For more information, explore other helpful articles on Python development best practices Real Python and VS Code configuration VS Code Python Tutorial.

Question & Answer :
I am using the following setup

  • macOS v10.14 (Mojave)
  • Python 3.7.1
  • Visual Studio Code 1.30
  • Pylint 2.2.2
  • Django 2.1.4

I want to use linting to make my life a bit easier in Visual Studio Code. However, for every import I have states “unresolved import”. Even on default Django imports (i.e. from django.db import models).

I presume it is because it is not seeing the virtual environment Python files.

Everything works just fine, but it’s starting to get annoying.

The interpreter choices I have are all system versions of Python. It does not seem to see my virtual environment Python at all (it is not in the same directory as my workspace, so that part makes sense).

If I set up the python.PythonPath in the settings.json file, it just ignores it and does not list my virtual environment path as an option. I also tried setting it up in my global Python settings, but it also does not show up.

Is there a quick fix to get it working?

The accepted answer won’t fix the error when importing own modules.

Use the following setting in your workspace settings .vscode/settings.json:

"python.autoComplete.extraPaths": ["./path-to-your-code"], 

Reference: Troubleshooting, Unresolved import warnings

UPDATE 2023

As mentioned by shmim python-language-server is deprecated and new closed source LSP Pylance’s setting is configured as follows:

"python.analysis.extraPaths": ["./path-to-your-code"]