-2

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

`> Executing task: 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).

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.

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

Doyeon
  • 7
  • 7
  • You are aware that simplejson is bo more than an externally maintained version of the json module built into the standard library? It was a thing in early Python 2 versions. But nowadays you should consider using the json module. – Klaus D. Nov 05 '20 at 06:26
  • thank you for the info! I’m very new to python and just following the steps from the tutorial which i paid... so .. :( but thanks ! – Doyeon Nov 26 '20 at 15:19

1 Answers1

1

I've reproduced this process and hope the following steps could help you

1.Activate the venv and install simplejson;

2.Run the helloworld.py in Terminal to make sure the script no error;

enter image description here

3.Configure the tasks.json, pay attention to use the venv's 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;

enter image description here

Molly Wang-MSFT
  • 7,943
  • 2
  • 9
  • 22
  • Happy that my answer helps you, it's appreciated that if you can mark it. – Molly Wang-MSFT Nov 27 '20 at 01:24
  • :) can i ask one more question? what if i want to access with the whole folder with python files? like not only the helloworld.py file. do i need to include the whole project directory? – Doyeon Nov 30 '20 at 03:02
  • Add `"env": { "PYTHONPATH": "${workspaceFolder}", }, "cwd": "${workspaceFolder}"` in launch.json, the parameter **workspaceFolder** means the path of the folder opened in VS Code, which is the whole current project folder. – Molly Wang-MSFT Nov 30 '20 at 05:20