0

I am trying to run a python file named cursesDb.py, but I get an error. That File import curses library, but when I use the sublime text editor, I can't run my program because an error occurs in this file: /usr/lib/python3.7/curses/__init__.py. I am using Linux Ubuntu 19 as my OS.

Somebody could tell me how could fix this? I am a beginner in python, exactly in these lines:

setupterm(term=_os.environ.get("TERM", "unknown")
**fd=_sys.__stdout__.fileno())**

The error occurs when I build ctr + b in sublime text, as follows below:

_curses.error: setupterm: could not find terminal

thanks!

FBruzzesi
  • 6,385
  • 3
  • 15
  • 37

1 Answers1

0

Most likely this is due to the fact that curses is trying to determine what terminal type to use to do things like output colors and manipulate the cursor position.

When you use a standard build system in Sublime Text, all it does is capture the output of your program and dump it to a panel; that is, it's not a terminal at all. So there's likely no TERM variable set, and even if there was it would be meaningless because curses isn't going to work anyway.

An important note in this regard is that the "dumb terminal" that Sublime uses to dump output doesn't accept input, so if your program is expecting to gather some sort of input from the user to do something, that will also fail.

To solve both of these problems, you can do something like this:

  1. Install the Terminus package, which provides a terminal inside of Sublime
  2. Open up your sublime-build file and add the following keys inside of the { } characters (anywhere within there is fine).

    "target": "terminus_exec",
    "cancel": "terminus_cancel_build",
    

Now when you run the build, Terminus will open an actual terminal and run your code inside. This is more the sort of environment that curses is expecting, and is also needed if your program needs to be in any way interactive.

More details can be found in this video on making any build system interactive with Terminus if needed. This may be of particular benefit if you're not sure how to find and open the build file that you're using.

OdatNurd
  • 21,371
  • 3
  • 50
  • 68