title: python curses remote debugging pdevd error in setupterm
body: <p>Is it possible to debug a curse program remotely in PyCharm? How to set it up? </p>
  
  <p>I followed the PyCharm 4.0.8 instruction, added this to the "<code>EXAMPLE.py</code>" from "<code>npyscreen-4.8.7</code>". </p>
  
  <pre><code>import pydevd
  pydevd.settrace('localhost', port=8899, stdoutToServer=False, stderrToServer=True)
  </code></pre>
  
  <p>And always it runs into an error in "<code>setupterm</code>": </p>
  
  <pre><code>$ PYTHONPATH=~/bin/pycharm-debug.egg python EXAMPLE.py
  Traceback (most recent call last):
    File "EXAMPLE.py", line 34, in &lt;module&gt;
      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
  </code></pre>
  
  <hr>
  
  <p>The problem is that pydevd changed environment "TERM" from "xterm" to "emacs". This can be verified by a little test program. </p>
  
  <pre><code>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"
  </code></pre>
  
  <ul>
  <li>If removing the two lines with "<code>pdevd</code>", the program succeeds. The "<code>TERM</code>" it prints out is "<code>xterm</code>". </li>
  <li>If change the 1st argument to "<code>setupterm</code>" into "<code>term='xterm'</code>", even with "<code>pydevd</code>" it succeeds. </li>
  </ul>
  
  <p>I guess the question is how to have "<code>pydevd</code>" setup the correct "<code>TERM</code>"?</p>