在Ubuntu上为Python3安装NCurses

6

我在安装 Python3ncurses 时遇到了问题。当我使用普通的 sudo apt-get install ncurses-dev 命令时,它似乎只是为 Python2 安装了。但是当我尝试运行 Python3 的脚本时,它会显示以下错误信息。

ImportError: No module named curses

你如何使得 ncursesPython3 中正常工作?
2个回答

8

我曾经遇到过同样的问题。问题出在我的Ubuntu系统上没有安装ncurses。为了解决这个问题,我运行了以下命令:

sudo apt-get install libncurses-dev

然后重新安装了Python。在我的情况下,使用的版本是:

pyenv install 3.8.1

当被问到是否要继续安装时,回答 y。

这解决了问题。


1

试试这个:

import curses

curses就是ncurses。它也内置在Python中,无需安装。

Welcome to Ubuntu 14.04.3 LTS (GNU/Linux 3.13.0-65-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Mon Oct 19 19:06:03 2015 from xxx.xxx.xxx.xxx
me@ubuntu:~$ python3
Python 3.4.0 (default, Jun 19 2015, 14:20:21) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import curses
>>> 

我正在使用Ubuntu 14.04.3 LTS。 - Solomon
这里有什么东西吗:/usr/lib/python3.4/curses - jgritty
1
我刚刚尝试了你的方法,当我输入"import curses"时,它显示找不到模块"_curses"。是的,我的文件夹里有相关内容。但是我发现有一个python3和一个python3.4的文件夹,感觉有点奇怪。 - Solomon
我觉得我找到了问题... Python自动运行3.5版本,所以无法识别3.4版本中的curses库。我不知道如何将默认版本修复为3.4,但可以通过运行"python3.4 main.py"来执行我的脚本。 - Solomon
让我们在聊天室中继续这个讨论:点击这里 - jgritty
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接