问题
I'm facing a weird problem.
Using Pycharm (please do not troll about this fact), I'm trying to launch a short app that uses ncurses
to render some things on my term.
While I can launch the project in a simple term without any problem, launching it from Pycharm raise the following error :
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/curses/__init__.py", line 33, in initscr
fd=_sys.__stdout__.fileno())
error: setupterm: could not find terminal
Process finished with exit code 0
As far as I can see, all is about terminal environment variables. Pycharm launch the project (Run or Debug) from its own instance of the terminal, and curses will not work with it. So, I am wondering how may I configure Pycharm to launch my project inside a regular terminal.
The project is using Python 2.7. Pycharm is in EAP version 129.258 (doesn't work with other versions, including stables)
Thanks for your attention.
K.
回答1:
I solved the curses debugging problem by attaching the debugger to a process.
- Start the program in a terminal
- Pycharm -> Tools -> Attach to Process
- Select my prog
- Done
Trying to attach as non-root requires additional ptrace access rights.
Explained here: http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails-with-ptrace-operation-not-permitted/#comment-141535
On my ubuntu machine:
echo 0 > /proc/sys/kernel/yama/ptrace_scope
(as root)
respectively set ptrace_scope to 0 in /etc/sysctl.d/10-ptrace.conf
回答2:
- Start PyCharm and make sure that ncurses is listed in File->Settings->Project Interpreter->Python Interpreter;
- if you have 2.7 and 3.x interpreters installed, make sure that correct one(supporting ncurses) is selected as default for the project from which you launch your application;
I more than sure that you have both 2.7 and 3.x installed on your machine - I had most of the issues with pycharm for case where both Python's branch were installed.
来源:https://stackoverflow.com/questions/17008372/pycharm-how-to-launch-for-a-standard-terminal-to-solve-an-issue-with-curses