简体   繁体   中英

Python in vscode

I have downloaded vs code in my windows 10 computer just, I want to learn python in it. So, I have installed some extensions like "Python" , "Python for VSCode" ,"code runner". But when I click on the run button (Ctrl+ALT+N) I am getting this error in my terminal:

python : The term 'python' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ python -u "e:\C File\Source file\practice.py"
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (python:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

But when I type py -u "e:\\C File\\Source file\\practice.py" instead of python -u "e:\\C File\\Source file\\practice.py" it is working,

Now what should I do to run this at one mouse click, I don't want to run the code by typing the command.

IMHO, most likely your 'Python' global environment variable is not set correctly.

But, since you mention that py -u [File Path] command seems to give you the output I can suggest that you change how "Code Runner" extension sends a Run command.

Steps:

  1. Click File>Preferences>Settings (shortcut Ctrl + , )
  2. Open "settings.json" file (refer to my attached GIF file for reference)
  3. Paste the following code lines at the end of this file ensuring you don't miss any commas (again refer to the attached GIF):

     "code-runner.executorMap": { "python": "py -u", },

This should change how the Code-Runner extension sends the Run Code command for Python files. Save the settings.json file and try running your code again using the same shortcut Ctrl + Alt + N ".

Does this fix your issue, Pranav? If not, maybe post a clipping of the error message again.

Link to the GIF file showing how to insert the code in settings.json file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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