是否可以在 PyCharm 中远程调试诅咒程序?如何设置?
我遵循 PyCharm 4.0.8 指令,将其添加到EXAMPLE.py
来自“”的“ npyscreen-4.8.7
”中。
import pydevd
pydevd.settrace('localhost', port=8899, stdoutToServer=False, stderrToServer=True)
并且总是在“ setupterm
”中遇到错误:
$ PYTHONPATH=~/bin/pycharm-debug.egg python EXAMPLE.py
Traceback (most recent call last):
File "EXAMPLE.py", line 34, in <module>
App.run()
File "/home/.../npyscreen-4.8.7/npyscreen/apNPSApplication.py", line 30, in run
return npyssafewrapper.wrapper(self.__remove_argument_call_main)
File "/home/.../npyscreen-4.8.7/npyscreen/npyssafewrapper.py", line 41, in wrapper
wrapper_no_fork(call_function)
File "/home/.../npyscreen-4.8.7/npyscreen/npyssafewrapper.py", line 83, in wrapper_no_fork
_SCREEN = curses.initscr()
File "/usr/lib64/python2.6/curses/__init__.py", line 33, in initscr
fd=_sys.__stdout__.fileno())
_curses.error: setupterm: could not find terminal
问题是 pydevd 将环境“TERM”从“xterm”更改为“emacs”。这可以通过一个小测试程序来验证。
import pydevd
pydevd.settrace('localhost', port=8899, stdoutToServer=False, stderrToServer=True)
import os as _os
import sys as _sys
import curses
print " my term: ", _os.environ.get("TERM", "unknown"), "\n"
print " my fd: ", _sys.__stdout__.fileno(), "\n"
print "\n ok 1 \n"
curses.setupterm(term=_os.environ.get("TERM", "unknown"),
#curses.setupterm(term='xterm',
fd=_sys.__stdout__.fileno())
print "\n ok 2 \n"
- 如果删除带有“
pdevd
”的两行,则程序成功。TERM
它打印出来的“”是“ ”xterm
。 - 如果将“”的第一个参数更改
setupterm
为“term='xterm'
”,即使使用“pydevd
”也成功。
我想问题是如何让“ pydevd
”设置正确的“ TERM
”?