Posted in Python, Visual Studio Code

How to solve the input() error in Visual Studio Code when you run the code in the integrated terminal

2020.12 Update:

Python extension of VS Code is better than before now, so the latest solution is:

  • Install Python and VS Code on your computer
  • Open a terminal (Powershell, CMD, etc.), input command “python” then Enter. Make sure you get the python version information. Input “exit()” to exit.
  • Install Python extension(by Microsoft) in VS Code
  • Open a folder as a Workspace in VS Code (on the top menu bar, click “File”, then click “Open Folder…”)
  • Create a .py file in the Workspace (you can do this by click the “+” sign on the tree panel)
  • Look at the left-bottom corner of VS Code. Choose the correct Python Interpreter.
  • Write you code in that .py file (no need to save it)
  • Press F5 on keyboard, then choose “Python File”
  • The result will show up on the integrated terminal (terminal window will pop out automatically) and it will let you input something and run the results.

In fact, this may be the only correct way to run Python in VS Code and you can debug with breakpoint in this way. Get used to it anyway.

And also, you can directly input command line in the integrated terminal and no need to use the third party terminal. But if you are more comfortable with third party terminal, that’s okay.

Older Contents for Reference:

This article was born some years ago but until lately I found the serious mistake in it. Now I fix it and I’m sure you can make it after you follow the steps. Sorry for those who searched this passage but left with depression.

First of all, you need to run the python code correctly in your Visual Studio Code, just having an annoying problem that you cannot deal with the input() error.

How do you know that? You can install an extension from VS Code Store named code runner(by Jun Han), and you will get a new right-click menu named Run Code in VS Code so that you can run the code in the integrated terminal of VS Code.

If you cannot run the python code in Visual Studio Code totally, this article may be not useful to help you with. You should check your environment, such as reinstall Python or VS Code.

Code runner is a very nice debug tool but it is read-only in the terminal so that you cannot deal with input().

To solve the problem is very easy:

  1. Install an extension named Python(by Microsoft) and you will get a new right-click menu in your editor.
  2. Keep on the editor’s UI and just save the .py file into your disk.
  3. Right click the editor’s UI and click the menu Run Python File in Terminal.
  4. Now you can get the Terminal on the bottom of the Visual Studio Code and you can input anything you want.
  5. Enjoy it!

Well, this solution is made for debugging in the integrated terminal. If you would like to save the file and run it in CMD or Powershell, that’s fine.

Deep in:

There are two kinds of terminal window in VS Code. One is called Output and the other is called Terminal. They are very different!

If you are using the extension named Code Runner, you will only open the Output window. The output window is read-only so that you cannot do any inputting, like inputting a string or an integer.

But the Terminal will support inputting anything because it is the same as Powershell(on Windows OS). It is more like a shadow of Powershell, integrating Powershell into the VS Code.

Hopefully you have understood it. Thanks for reading!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.