Resolving Python Module 'numpy' has no 'xxxx' member error message in Visual Studio Code

怼烎@ 2023-06-19 02:30 103阅读 0赞

While writing some Python code in Visual Studio Code that calls some Numpy classes, Pylint error messages appear complaining about non-existing Numpy members, e.g. the log2 method, and red wavy lines underline the offending code, as shown in the screenshot below. 报错内容。
watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hhMWZfQXdha2U_size_16_color_FFFFFF_t_70
One way to clear this up is to get Pylint to white-list Numpy using Visual Studio Code‘s Settings.

  1. In Visual Studio Code, select File | Preferences | Settings.

    The settings.json file is displayed in the editor. 在Settings中搜索找到“settings.json”。

  2. watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hhMWZfQXdha2U_size_16_color_FFFFFF_t_70 1
  3. Click the Workspace Settings tab.

    The settings appear in the editor.
    watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hhMWZfQXdha2U_size_16_color_FFFFFF_t_70 2

  4. In the editor, type in the following and save the file.

    在json文件中写入{ “python.linting.pylintArgs” : [ “—extension-pkg-whitelist=numpy” ] }

    watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hhMWZfQXdha2U_size_16_color_FFFFFF_t_70 3

  5. Close and reopen the folder in Visual Studio Code.

    The missing member messages and the red wavy underlines no longer appear. 报错消失。watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0hhMWZfQXdha2U_size_16_color_FFFFFF_t_70 4

发表评论

表情:
评论列表 (有 0 条评论,103人围观)

还没有评论,来说两句吧...

相关阅读