16

I am trying to use Curses in PyDev in Eclipse in Win7.

I have installed Python 3.2 (64bit) and curses-2.2.win-amd64-py3.2. When I input the following testing codes into PyDev:

import curses  

myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")    
myscreen.refresh()
myscreen.getch()     
curses.endwin()

It did not show any syntax error, so I think the curses was installed correctly.

However, when I ran it as Python Run, the output showed: Redirection is not supported. I do not know where this problem comes from. I googled a lot but can't find related information.

LJNielsenDk
  • 1,414
  • 1
  • 16
  • 32
shaosh
  • 657
  • 2
  • 8
  • 30

5 Answers5

18

Recent PyCharm versions (I am currently running 2017.2, not sure when this option was added, or if it has been there the entire time) have the option "Emulate terminal in output console". Curses works with this option checked.

enter image description here

codeape
  • 97,830
  • 24
  • 159
  • 188
  • 1
    When I enable this, it just shows be a flashing black box. I can't see the options I am going through. – Giacomo Jan 06 '19 at 13:57
  • 1
    For future readers, this is enabled by selecting the drop down up the top of the window where you have your run configurations and selecting "Edit Configurations". You can also find this under "Run" -> "Edit Configurations" as of Pycharm 2022 – Kit Feb 16 '23 at 07:10
10

You cannot expect to use curses with a non-terminal.

Probably you get this because you are running the script from inside an IDE, like PyCharm or any other.

All IDEs do provide consoles that are not terminals, so that's where the problem comes from.

sorin
  • 161,544
  • 178
  • 535
  • 806
1

For a Pycharm user the solution given by codeape works fine :

Snapshot

0

You can't use any IDE to run python files with the curses package. I used to run in pycharm and naturally couldn't run.

Change to the command line to run:

for testing follow my following steps

  1. on desktop open notepad and copy paste the code and save it as filename.py
  2. open command line change directory to desktop use below command cd Desktop and hit enter type python example.py and hit enter, your program will definitely run
Milo
  • 3,365
  • 9
  • 30
  • 44
ratanek
  • 1
  • 1
0

My workaround is to create a Run Configuration that calls a curses script. The little overhead is worth not having to switch to the terminal and manually run the script hundreds of times a session. I use Intellij but I imagine the process should be similar in PyCharm.

The desired result is the convenience of a button to run the script:

Intellij Run Scripts

First create a script that calls the entry script, for instance:

ptyhon name-of-script.py

Then, to create a configuration for each script:

  1. Go to Edit configuration.
  2. Click the plus button and add a Shell Script.
  3. Enter the path to a shell script.

Intellij Shell Script Configuration

Here is a picture of a directory with a couple of sample scripts.

Directory tree of ncurses scripts

I use this process to view my progress. My curses scripts are very modest so fortunately I can live without a debugger.

chelista
  • 73
  • 7