Unresolved imports in Azure function in Visual Studio Code

Jean David Ruvini 85 Reputation points
2024-11-21T18:17:16.28+00:00

Hi,

We are working on a Python Azure Function that utilizes a custom library. This library is specified in the requirements.txt file and is installed into a .venv virtual environment. The function operates correctly during local debugging and when deployed to Azure.

However, within VS Code, the imports from this custom library are marked as unresolved, and IntelliSense does not provide suggestions for it.

Steps we've tried:

  1. Set the Python interpreter to the .venv environment.
  2. Configured "python.analysis.extraPaths" in settings.json to include paths to the custom library.
  3. Enabled "python.terminal.activateEnvironment": true to ensure the environment activates in all terminals.
  4. Set "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python" in settings.json.

Any suggestion?
Thanks

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,263 questions
{count} votes

Accepted answer
  1. robert joseph 80 Reputation points
    2024-11-21T18:48:38.9566667+00:00

    It sounds like you've already taken the right steps to configure the environment, but IntelliSense is still having trouble recognizing the custom library. Here are a few more things you can try:

    1. Rebuild the Virtual Environment: Sometimes, the virtual environment might not properly link with VS Code. Try deleting the .venv folder, recreate it, and reinstall your dependencies with pip install -r requirements.txt.
    2. Check VS Code Python Extension: Ensure that the Python extension in VS Code is up to date. Occasionally, issues with IntelliSense can arise due to outdated extensions.
    3. Use the Correct Python Path: Double-check that the path to the interpreter in VS Code points to the correct virtual environment. Go to the command palette (Ctrl+Shift+P), search for “Python: Select Interpreter,” and ensure you select the correct one from .venv.
    4. Check if the Library is Installed Correctly: Open a terminal in VS Code and activate your .venv by running source .venv/bin/activate (or .venv\Scripts\activate for Windows). Then, check if your custom library is installed with pip list.
    5. Add Library Path in settings.json: You might also need to explicitly add the path to the custom library in the "python.autoComplete.extraPaths" section of settings.json, not just python.analysis.extraPaths.

    If nothing works, try restarting VS Code and the Python language server after making changes to the configuration.

    Let me know how it goes!

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.