skip to Main Content

A newbie here, I’ve installed the python and code runner extension in VS code and every time I run a Python program by clicking the right arrow(run code) button, it will say python -u <program directory> in my terminal window. Usually there are no issues, but when I tried importing pip modules such as numpy or pandas, it will say ModuleNotFoundError.

Yes, I’ve installed those modules in my cmd and it works in my default Python IDLE. I tried many things, such as watching Youtube tutorials on how to install pip modules in VS Code but to no avail. But it turns out all this time all I need to do is just change python to py in the terminal, i.e. I need to type py -u <program directory> in the terminal for it to work. My question is, how do you change it so that when I click the right arrow button it just by default says py instead of python so I don’t have to change it manually.
Also, another thing is when I tried creating venv with python -m venv or python3 -m venv it seems to be missing the Scripts folder(which contains the Activate.psi file) and instead has a bin folder. But when I tried with py -m venv it had the Scripts folder. Is this normal?

Edit: I also found out that when running python --version or python3 --versionin my cmd it says Python 3.10.9 but when running py --version it says Python 3.11.4. Maybe it’s because I tried to uninstall and reinstall Python at some point in the past. I’m just wondering if this discrepancy is the reason for my issue.

2

Answers


  1. To change the command used by the Code Runner for Python files, change the code-runner.executorMap setting. Ex.

    "code-runner.executorMap": {
        "python": "py -u",
    }
    
    Login or Signup to reply.
  2. If you get errors referencing packages, you should choose the correct interpreter for vscode (Ctrl+Shift+P –> Python: Select Interpreter) and use the official extension Python (Run Python File) to execute the script. The interpreter you choose for vscode does not work with the Code Runner extension.

    It is useful for you to follow this document to start using python in vscode now.

    As for changing the command for Code Runner, you can refer to this answer. Although that is changing the Java command, the operation is the same.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search