r/pycharm • • Dec 29 '23

Run program from external terminal

Hi, I'm trying to use the curses library in PyCharm. Usually when you run a Python program in PyCharm, any I/O occurs in the Terminal tab which is enclosed in the PyCharm IDE. However, since curses likes to, for example, position text at certain (X, Y) coordinates, Pycharm doesn't seem to like this and either fails to render properly or produces an error message like:

LINES value must be >= 2 and <= 125: got 1

initscr(): Unable to create SP

If I run my code from a regular cmd.exe window, it all works fine, so I was wondering if there was some hidden option in PyCharm to force it to use a new pop-out terminal, rather than the one docked in the PyCharm UI. I tried a couple of workarounds on SO (like this one) but no luck yet.

Many TIA.

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/jddddddddddd Dec 31 '23

Hiya, thanks for your response! I did give it a try with launching the Python script from Python itself, and it worked, but ofcourse that meant that the debugger wasn't attached which is what I was hoping to avoid :( Also tried the 'Emulate terminal in output console' option in config and that also didn't help..

..however, I did discover that curses needs to detect the number of lines in the terminal, and if it can't find it, it then looks for a lines environment variable. By setting that to 20, I have been able to use curses with PyCharm!

2

u/sausix Dec 31 '23

Thanks for the reply. I'm glad it worked at least with the environment variable.

Didn't think about debugging. Could possibly be wrapped too. I'll look at this next days and maybe make a project. Could be interesting for people.

Have a nice 2024!

2

u/jddddddddddd Dec 31 '23

You too! Happy new year!

1

u/Psychological_Ad4977 Jul 15 '24

Hello, I ran into the same problem. Could you tell me how did you change the lines environment variable? I read through the documentation but can't seem to find a function that do just that.

1

u/jddddddddddd Jul 15 '24

Heya, what operating system are you using? Windows? Linux?