How can I avoid NameError from input() in Sublime Text 4, using SublimeREPL on Mac OS 12.1?

This answer is assuming you're either running Linux or macOS and already have Python 3 installed on your system.

You're getting the NameError because SublimeREPL is using Python 2, an old version that passed its end-of-life support over 2 years ago and was deprecated long before that. Not everyone has ported their codebases over to the current Python 3, however, which is why you still find it on some systems. If you're just starting to learn Python, you absolutely should start by using Python 3, which is the present and future of the language, then after you are proficient you can learn the differences between it and Python 2.

The good news is that you likely already have Python 3 installed on your system if you're using a recent release of either Linux or macOS, and it's relatively straightforward to point SublimeREPL to it. To start, open Sublime and select Preferences → Browse Packages… on Linux or Sublime Text → Preferences → Browse Packages… on macOS. Your system's file browser will open to a folder called Packages that contains at least 2 subfolders - SublimeREPL and User (depending on how many plugins you've installed so far). Open the SublimeREPL folder, then config, then Python. Drag the file called Main.sublime-menu to your Sublime window and set its syntax to JSON (View → Syntax → JSON).

Line 53 should be this:

"cmd": ["python", "-u", "$file_basename"],

Change python to python3:

"cmd": ["python3", "-u", "$file_basename"],

Additionally, in case you use the REPL directly in the future, change lines 22 and 39 so they say python3 as well.

Save the file, then switch back to your original Python file and use the Python_Run build system. You should be able to use your original test code now and get the proper results.


For reference, the Sublime Text 4 Packages folder is located in different places on different operating systems:

  • Linux: ~/.config/sublime-text/Packages
  • macOS/OS X: ~/Library/Application Support/Sublime Text/Packages
  • Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text\Packages
  • Windows Portable Install: InstallationFolder\Sublime Text\Data\Packages