简体   繁体   English

python vscode ImportError:没有名为simplejson的模块

[英]python vscode ImportError: No module named simplejson

i have import simplejson in my code, and installed using pip install simplejson using python3 so as i checked, it perfectly runs in my terminal opening the file but when i try to build in VScode, it shows an error like, see the error in this link as我在我的代码中导入了 simplejson,并使用 python3 使用 pip install simplejson 进行了安装,所以当我检查时,它在我打开文件的终端中完美运行,但是当我尝试在 VScode 中构建时,它显示了一个错误,例如,请参阅此错误链接

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

Traceback (most recent call last): File "/Users/Tony/Documents/python3.9/helloworld.py", line 1, in import simplejson as json ImportError: No module named simplejson The terminal process "/bin/bash '-c', 'python /Users/Tony/Documents/python3.9/helloworld.py'" failed to launch (exit code: 1).回溯(最近一次调用最后一次):文件“/Users/Tony/Documents/python3.9/helloworld.py”,第 1 行,在 import simplejson as json ImportError: No module named simplejson The terminal process "/bin/bash'- c', 'python /Users/Tony/Documents/python3.9/helloworld.py'" 无法启动(退出代码:1)。

but it still runs on my terminal.但它仍然在我的终端上运行。 and if i check the pip list, simplejson is still there and i also tried to use different version of python too.如果我检查 pip 列表,simplejson 仍然存在,我也尝试使用不同版本的 python。

and I have activated the virtual environment enter image description here and i am using the last one which i recently activated.我已经激活了虚拟环境在此处输入图像描述,我正在使用我最近激活的最后一个。

please help me to find the error.请帮我找出错误。 i don't really know where to fix thanks我真的不知道在哪里修复谢谢

I've reproduced this process and hope the following steps could help you我已经复制了这个过程,希望以下步骤可以帮助你

1.Activate the venv and install simplejson ; 1.激活venv并安装simplejson

2.Run the helloworld.py in Terminal to make sure the script no error; 2.在终端运行helloworld.py ,确保脚本没有错误;

在此处输入图片说明

3.Configure the tasks.json , pay attention to use the venv's pythonpath ; 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.Tasks:Run Task; 4.Tasks:运行任务;

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM