TransWikia.com

"Unresolved import" error for Python built-ins in vscode on macOS

Stack Overflow Asked by safetymonkey on December 1, 2021

I’m setting up a new macOS Catalina machine and I am receiving the following errors in the Problems window which appear to be originating from the Python Language Server (as opposed to a linter). All imports are failing, these are just some examples.

_helpers.py
  unresolved import 'datetime' Python(unresolved-import) [2, 8]
  unresolved import 'json' Python(unresolved-import) [3, 8]
  unresolved import 'logging' Python(unresolved-import) [4, 8]

These are showing up for built-in libraries as well as third party libraries I’m importing, most notably Google App Engine via the Gcloud SDK. All of the searching I’ve done suggests it’s a problem with the paths, but nothing I’ve tried works. Also worth noting that if I go into the Terminal window in vscode, open an interactive Python shell and import these libraries, everything works.

My system:

  • macOS Catalina 10.15.6
  • Python installed via pyenv (pyenv installed via homebrew)
  • Pyenv global version: 3.8.3
  • Pyenv local version for current repository: 2.7.18 + 3.8.3 (The repo is still on Python 2 but some of our build tools require Python 3)

Here’s my settings files:

// User settings.json
{
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "python.languageServer": "Microsoft",
    "python.pythonPath": "~/.pyenv/shims/python",
    "python.analysis.downloadChannel": "stable", 
}
// Workspace settings.json (in .vscode)
{
    "files.exclude": {
        "**/*.pyc": true
    },
    "python.pythonPath": "${workspaceFolder}/Venv/bin/python",
    "python.autoComplete.extraPaths": [
        "${workspaceFolder}/lib/",
        "~/google-cloud-sdk/",
        "~/google-cloud-sdk/platform/google_appengine",
        "~/google-cloud-sdk/platform/google_appengine/lib/",
        "~/google-cloud-sdk/lib"
    ],
    "files.associations": {
        "*.html": "jinja-html"
    }
}

I’m losing my mind here. Any help would be greatly appreciated.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP