确定 sys.argv 的模块路径时出错 - 每个 python 程序都会返回此错误

问题描述 投票:0回答:2

这个错误在我尝试安装plotly.graph_objects之后开始发生,现在每次我运行任何python程序时都会弹出这个错误。我现在已经卸载了该模块,但错误仍然存在。

即使尝试执行打印语句, 这是它显示的错误:

E+00000.063: Error determining module path for sys.argv

             Traceback (most recent call last):
               File "c:\Users\User\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 296, in run_module
                 spec = find_spec(options.target)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
               File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\importlib\util.py", line 94, in find_spec
                 parent = __import__(parent_name, fromlist=['__path__'])
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             ModuleNotFoundError: No module named 'plotly==5'

             Stack where logged:
               File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 198, in _run_module_as_main
                 return _run_code(code, main_globals, None,
               File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\runpy.py", line 88, in _run_code
                 exec(code, run_globals)
               File "c:\Users\User\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy\__main__.py", line 39, in <module>
                 cli.main()
               File "c:\Users\User\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 430, in main
                 run()
               File "c:\Users\User\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\server\cli.py", line 300, in run_module
                 log.swallow_exception("Error determining module path for sys.argv")
               File "c:\Users\User\.vscode\extensions\ms-python.python-2023.4.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher/../..\debugpy/..\debugpy\common\log.py", line 215, in swallow_exception
                 _exception(format_string, *args, **kwargs)
python path sys
2个回答
3
投票

找到解决办法!如果您使用的是 vs code,在“编辑”下方的左上角附近有一个带有绿色三角形的下拉框,上面写着“Python”,如果它位于“Python:模块”上,请将其更改为“Python:文件”,这就是为我修好了。花了3天!


0
投票

只是为了在OP的答案中添加更多信息。运行文件和模块是有区别的。

Debug Console
中看到的错误消息可能类似于以下内容:

/usr/local/bin/python3: Error while finding module specification for 'hello.py' (ModuleNotFoundError: __path__ attribute not found on 'hello' while trying to find 'hello.py').
Try using 'hello' instead of 'hello.py' as the module name.

这可以在配置 Docker 容器入口点的文档中看到。

对于模块:

{
  "tasks": [
    {
      "type": "docker-run",
      "label": "docker-run: debug",
      "dependsOn": ["docker-build"],
      "python": {
        "module": "myapp"
      }
    }
  ]
}

对于文件:

{
  "tasks": [
    {
      "type": "docker-run",
      "label": "docker-run: debug",
      "dependsOn": ["docker-build"],
      "python": {
        #"args": ["-h"],
        "file": "hello.py"
      }
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.