Python version command fails with "NameError"
When attempting to check the Python version by entering "python3 --version," a common error encountered is "NameError: name 'python3' is not defined." This issue stems from the misconception that Python syntax should be used in this command.
Python3 is not a command within the Python interpreter; rather, it is the Python binary itself. To display the Python version, open a command console (such as terminals in Linux or Mac, or Command Prompt in Windows). Avoid typing these commands at the Python prompt (denoted by ">>>" or "In [number]:").
Many other commands are also commonly mistaken for Python syntax and should be executed in the command prompt. Notable examples include:
If arguments are appended to these commands, a SyntaxError will be thrown. However, the underlying issue remains the same: these commands are meant to be executed outside of the Python interpreter.
The above is the detailed content of Why does 'python3 --version' throw a 'NameError: name 'python3' is not defined'?. For more information, please follow other related articles on the PHP Chinese website!