Possible bug? Debugger error - <NameError: name is not defined> only in virtual environment
Hello, How to fix the next problem? I do simple things:
1. Create virtual environment with python37 using pycharm without any packages (C:\Users\username\virtualenvs\debug_problem\Scripts\python.exe).
2. Write some code and try to debug it (see screenshot).
3. In breakpoint mode (line 3) I press Shift+Alt+E and execute code line 3 in console.
4. Then in console just call variable j and get an errror:
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
NameError: name 'j' is not defined
If I do not use virtual environment there is no such problem.
Windows 10 x64.
PyCharm 2019.3 (Professional Edition)
Build #PY-193.5233.109, built on November 28, 2019
Runtime version: 11.0.4+10-b520.11 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1978M
Cores: 6
Registry:
Non-Bundled Plugins: com.andrey4623.rainbowcsv, com.leinardi.pycharm.pylint, net.seesharpsoft.intellij.plugins.csv
Please sign in to leave a comment.
Debug messages with PYCHARM_DEBUG=True:
C:\Users\osipov\virtualenvs\debug_problem\Scripts\python.exe "C:\Program Files\JetBrains\PyCharm 2019.2.3\plugins\python\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 54360 --file "C:/Debug problem/describe.py"
Using Cython speedups
Unable to load jupyter_debug plugin
Executing file C:/Debug problem/describe.py
arguments: ['C:/Debug problem/describe.py']
PYDEVD_FILTER_LIBRARIES False
Started in multiproc mode
('Connecting to ', '127.0.0.1', ':', '54360')
('Connected.',)
debugger: received >>99 -1 54361
<<
Received command: ??? 99 -1 54361
Received port 54361
pydev debugger: process 14736 is connecting
('Connecting to ', '127.0.0.1', ':', '54361')
Connected to pydev debugger (build 193.5233.109)
('Connected.',)
debugger: received >>501 1 0.1 WIN
<<
Received command: CMD_VERSION 501 1 0.1 WIN
sending cmd --> CMD_VERSION @@BUILD_NUMBER@@
debugger: received >>101 5
<<
Received command: CMD_RUN 101 5
debugger: received >>111 3 python-line c:/debug problem/describe.py 3 some_func THREAD None None
<<
Received command: CMD_SET_BREAK 111 3 python-line c:/debug problem/describe.py 3 some_func THREAD None None
Added breakpoint:c:\debug problem\describe.py - line:3 - func_name:b'some_func'
debugger: received >>146 9 SHOW_RETURN_VALUES 1
122 7 python-BaseException None None 0 1 0
<<
Received command: CMD_SHOW_RETURN_VALUES 146 9 SHOW_RETURN_VALUES 1
Show return values: True
Received command: CMD_ADD_EXCEPTION_BREAK 122 7 python-BaseException None None 0 1 0
Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x000001876C1FB588>}
sending cmd --> CMD_THREAD_CREATE <xml><thread name="MainThread" id="pid_14736_id_1681134785352" /></xml>
Suspending at breakpoint in file: C:/Debug problem/describe.py on line 3
sending cmd --> CMD_THREAD_SUSPEND <xml><thread id="pid_14736_id_1681134785352" stop_reason="111" message="" suspend_type="frame_eval"><frame id="1681149376200" name="some_func" file="C:\Debug problem\describe.py" line="3"></frame><frame id="1681146723240" name="<module>" file="C:\Debug problem\describe.py" line="9"></frame></thread></xml>
debugger: received >>114 11 pid_14736_id_1681134785352 1681149376200 FRAME
<<
Received command: CMD_GET_FRAME 114 11 pid_14736_id_1681134785352 1681149376200 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x000001876C501C08>')
sending cmd --> CMD_GET_FRAME <xml><var name="var_t" type="str" qualifier="builtins" value="make some actions" /> </xml>
import sys; print('Python %s on %s' % (sys.version, sys.platform))
debugger: received >>121 13 pid_14736_id_1681134785352 1681149376200 FRAME import sys; print('Python %s on %s' % (sys.version, sys.platform))@LINE@
<<
Received command: CMD_CONSOLE_EXEC 121 13 pid_14736_id_1681134785352 1681149376200 FRAME import sys; print('Python %s on %s' % (sys.version, sys.platform))@LINE@
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalConsoleExec object at 0x000001876C501CC8>')
sending cmd --> CMD_EVALUATE_EXPRESSION <xml><var name="" type="bool" qualifier="builtins" value="False" /> </xml>
debugger: received >>114 15 pid_14736_id_1681134785352 1681149376200 FRAME
<<
Received command: CMD_GET_FRAME 114 15 pid_14736_id_1681134785352 1681149376200 FRAME
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x000001876C20A648>')
sending cmd --> CMD_GET_FRAME <xml><var name="sys" type="module" qualifier="builtins" value="%3Cmodule %27sys%27 %28built-in%29>" isContainer="True" /> <var name="var_t" type="str" qualifier="builtins" value="make some actions" /> </xml>
j = '123'
debugger: received >>121 17 pid_14736_id_1681134785352 1681149376200 FRAME j = '123'@LINE@
<<
Received command: CMD_CONSOLE_EXEC 121 17 pid_14736_id_1681134785352 1681149376200 FRAME j = '123'@LINE@
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalConsoleExec object at 0x000001876C501C88>')
sending cmd --> CMD_EVALUATE_EXPRESSION <xml><var name="" type="bool" qualifier="builtins" value="False" /> </xml>
debugger: received >>114 19 pid_14736_id_1681134785352 1681149376200 FRAME
<<
Received command: CMD_GET_FRAME 114 19 pid_14736_id_1681134785352 1681149376200 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x000001876C501CC8>')
sending cmd --> CMD_GET_FRAME <xml><var name="sys" type="module" qualifier="builtins" value="%3Cmodule %27sys%27 %28built-in%29>" isContainer="True" /> <var name="var_t" type="str" qualifier="builtins" value="make some actions" /> </xml>
j
debugger: received >>121 21 pid_14736_id_1681134785352 1681149376200 FRAME j@LINE@
<<
Received command: CMD_CONSOLE_EXEC 121 21 pid_14736_id_1681134785352 1681149376200 FRAME j@LINE@
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalConsoleExec object at 0x000001876C501D08>')
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2019.2.3\plugins\python\helpers\pydev\_pydevd_bundle\pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
NameError: name 'j' is not defined
sending cmd --> CMD_EVALUATE_EXPRESSION <xml><var name="" type="bool" qualifier="builtins" value="False" /> </xml>
debugger: received >>114 23 pid_14736_id_1681134785352 1681149376200 FRAME
<<
Received command: CMD_GET_FRAME 114 23 pid_14736_id_1681134785352 1681149376200 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x000001876C519948>')
sending cmd --> CMD_GET_FRAME <xml><var name="sys" type="module" qualifier="builtins" value="%3Cmodule %27sys%27 %28built-in%29>" isContainer="True" /> <var name="var_t" type="str" qualifier="builtins" value="make some actions" /> </xml>
This error appears only when I define variables in console which uses in current breakpoint function:
Hi,
Looks like this bug https://youtrack.jetbrains.com/issue/PY-38378
Will be fixed in the next minor update.
Ok, thanks!
In most cases, this error is triggered when Python sees a variable name (Global or Local) and doesn't know what it's for. These errors can happen if you forget to initialize a variable , if you misspell a variable, or if you misspell a reserved word such as "True". Before you use the global variable in your function for reading, it must be first initialized somewhere: either outside of the function or inside it.