There are some possibilties:
In the pydevd debugger code.py the line variable is not initialized properly. The problem can be related to an incorrect installation or configuration of the debugger in Visual Studio as it was mentioned in comment section under question. You can try to run the code without using the IDE (for example, from the command line). If the error does not occur, then the problem is related to IDE.
Broken python core environment. Try running the code on another version Python with clean packages to eliminate the possibility of conflict with installed packages or environment settings.