python vscode导入错误:没有名为simplejson的模块

2024-05-16 04:09:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我在代码中导入了simplejson,并使用pip安装了simplejson,使用python3安装了simplejson 所以,正如我所检查的,它完美地运行在我打开文件的终端中,但是当我尝试构建VScode时,它显示了一个错误,如, see the error in this linkas

`>;执行任务:python/Users/Tony/Documents/python3.9/helloworld.py<

回溯(最近一次呼叫最后一次): 文件“/Users/Tony/Documents/python3.9/helloworld.py”,第1行,在 将simplejson导入为json ImportError:没有名为simplejson的模块 终端进程“/bin/bash'-c”、“python/Users/Tony/Documents/python3.9/helloworld.py”未能启动(退出代码:1)

但它仍然在我的终端上运行。如果我查看pip列表,simplejson仍然存在,我也尝试使用不同版本的python

我已经激活了虚拟环境enter image description here 我正在使用最近激活的最后一个

请帮我找出错误。我真的不知道去哪里修理谢谢


Tags: pip文件the代码py终端错误vscode
1条回答
网友
1楼 · 发布于 2024-05-16 04:09:31

我复制了这个过程,希望以下步骤可以帮助您

1.激活venv并安装simplejson

2.在终端中运行helloworld.py,确保脚本没有错误

enter image description here

3.配置tasks.json,注意使用venv的pythonpath

"version": "2.0.0",
    "tasks": [
        {
            "label": "run python file",
            "type": "shell",
            "command": "/venv's pythonpath/ helloworld.py",
            "group": {
                "kind": "test",
                "isDefault": true
            },
            "problemMatcher": [
                "$tsc"
            ]
        }
    ]

4.任务:运行任务

enter image description here

相关问题 更多 >