Error no module named curses
Asked Answered
B

5

21

When I try to run the following code...

from telnetsrvlib import *

if __name__ == '__main__':
"Testing - Accept a single connection"
class TNS(SocketServer.TCPServer):
    allow_reuse_address = True

class TNH(TelnetHandler):
    def cmdECHO(self, params):
        """ [<arg> ...]
        Echo parameters
        Echo command line parameters back to user, one per line.
        """
        self.writeline("Parameters:")
        for item in params:
            self.writeline("\t%s" % item)
    def cmdTIME(self, params):
        """
        Print Time
        Added by dilbert
        """
        self.writeline(time.ctime())

logging.getLogger('').setLevel(logging.DEBUG)

tns = TNS(("0.0.0.0", 8023), TNH)
tns.serve_forever()

I get this error

Traceback (most recent call last):
File ".\telserv.py", line 1, in <module>
from telnetsrvlib import *
File "C:\Python27\lib\site-packages\telnetsrvlib-1.0.2-py2.4.egg\telnetsrvlib.py", line 31, in <module>
import curses.ascii
  File "C:\Python27\lib\curses\__init__.py", line 15, in <module>
from _curses import *

I am running python 2.7 and have imported the telnetsrvlib library and I am running the code on windows 7. Any help would be appreciated.

Braziel answered 1/7, 2013 at 17:20 Comment(3)
install curses (I think in windows its ncurses) your telnetserver library may not be compatible with windows youtube.com/watch?v=V_MNiXCPQAYSd
If memory serves, this is also the error you'll see if you have a circular import. If A imports B imports C imports B, B will be unavailable but also unloadable when C attempts to import it, so you'll get an error.Foust
you can even find the source code and paste it into the lib folder! After that, importing will go on as usual. <!-- begin snippet: js hide: true console: true babel: false --> <!-- language: lang-html --> <h1>Maker's Effect</h1> <input type = 'text' value = 'Enter Anything to Test your Keyboard : '/> <input type = 'button' value = ' Done! '/> <!-- end snippet -->Ionopause
A
13

Install the UniCurses module from here: https://pypi.python.org/pypi/UniCurses

You may need to alter some of your code in order to use it, as it provides the functionality of NCurses, not the vanilla curses library.

Unfortunately, no direct Python for Windows port of curses exists.

Angkor answered 1/7, 2013 at 17:28 Comment(2)
Thanks it was an issue with the default curses moduleBraziel
Is there any doc for Unicurses? This was about all Google came up with: github.com/Chiel92/unicursesCallida
M
16

You could also look into installing the curses module from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses.

It allows python's native curses to be used on Windows, so all your standard python curses code can be used.

Misguided answered 10/8, 2013 at 15:44 Comment(0)
C
15

That works for me:

pip install windows-curses
Chaparro answered 12/7, 2019 at 8:56 Comment(0)
A
13

Install the UniCurses module from here: https://pypi.python.org/pypi/UniCurses

You may need to alter some of your code in order to use it, as it provides the functionality of NCurses, not the vanilla curses library.

Unfortunately, no direct Python for Windows port of curses exists.

Angkor answered 1/7, 2013 at 17:28 Comment(2)
Thanks it was an issue with the default curses moduleBraziel
Is there any doc for Unicurses? This was about all Google came up with: github.com/Chiel92/unicursesCallida
B
6

inspired by @YKB, I did this for Ubuntu 16.04 and Python3.5.2,

sudo apt-get install libncurses5-dev,

and then go to source code of Python, and make, two new files are created.

_curses.cpython-35m-x86_64-linux-gnu.so
_curses_panel.cpython-35m-x86_64-linux-gnu.so

And then copy them to lib-dynload folder at where you installed your python.

Burne answered 23/3, 2017 at 13:40 Comment(0)
P
4

Got the same error with Python 3.4 on Ubuntu 14.04 and here is how I fixed it.

My /usr/local/lib/python3.4/lib-dynload/ directory did not have the following files -

_curses.cpython-34m.so
_curses_panel.cpython-34m.so

Got a copy of the latest Python 3.4.2 source. Then (extracted &) compiled it:

./configure
make

Now the .so files I need were in build/lib.linux-i686-3.4/ and I copied them to /usr/local/lib/python3.4/lib-dynload/.

Polyptych answered 6/2, 2015 at 20:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.