pythonvisual-studio-codepipvscode-code-runner

How do you change your default Code Runner execution command in VS Code?


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.


Solution

  • 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",
    }