Python 错误没有名为curses的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17410116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:07:24  来源:igfitidea点击:

Error no module named curses

pythonwindowspython-2.7telnetcurses

提问by Strommer

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.

我正在运行 python 2.7 并导入了 telnetsrvlib 库,我正在 Windows 7 上运行代码。任何帮助将不胜感激。

采纳答案by gorzek

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

从这里安装 UniCurses 模块: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.

您可能需要更改一些代码才能使用它,因为它提供了 NCurses 的功能,而不是普通的 curses 库。

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

不幸的是,不存在直接用于 Windows 的 Python 端口的诅咒。

回答by Johan

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

您还可以从这里查看安装 curses 模块: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.

它允许在 Windows 上使用 python 的原生诅咒,因此可以使用所有标准的 python 诅咒代码。

回答by YKB

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

在 Ubuntu 14.04 上使用 Python 3.4 遇到了同样的错误,这是我修复它的方法。

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

我的/usr/local/lib/python3.4/lib-dynload/目录没有以下文件 -

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

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

得到一份最新的 Python 3.4.2源代码。然后(提取 &)编译它:

./configure
make

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

现在.so我需要的文件在里面build/lib.linux-i686-3.4/,我将它们复制到/usr/local/lib/python3.4/lib-dynload/.

回答by TonyTony

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

受到@YKB 的启发,我为 Ubuntu 16.04 和 Python3.5.2 做了这个,

sudo apt-get install libncurses5-dev,

sudo apt-get install libncurses5-dev,

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

然后转到Python的源代码,和make,创建了两个新文件。

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

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

然后将它们复制到lib-dynload安装 python 的文件夹中。

回答by Yura G

That works for me:

这对我行得通:

pip install windows-curses

回答by VICTOR STEVE

That works for me:

这对我行得通:

pip install windows-curses

Type in the anaconda prompt or your IDE

输入 anaconda 提示符或您的 IDE