英文:
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 --version
in 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.
英文:
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 --version
in 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.
答案1
得分: 1
更改Code Runner用于Python文件的命令,请修改 code-runner.executorMap
设置。例如,
"code-runner.executorMap": {
"python": "py -u",
}
英文:
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",
}
答案2
得分: 0
如果您在引用包时遇到错误,请选择正确的vscode解释器(Ctrl+Shift+P --> Python: Select Interpreter
),并使用官方扩展 Python(Run Python File
)来执行脚本。您为vscode选择的解释器与 Code Runner 扩展不兼容。
您可以参考此文档来开始在vscode中使用Python。
至于更改Code Runner的命令,您可以参考此答案。尽管是更改Java命令,但操作方式相同。
英文:
If you get errors referencing packages, you should choose the correct interpreter for vscode (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> --> 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论