【问题标题】:Install NCurses on python3 for Ubuntu在 python3 上为 Ubuntu 安装 NCurses
【发布时间】:2015-10-21 23:31:21
【问题描述】:

我在为 Python3 安装 ncurses 时遇到问题。当我执行正常的sudo apt-get install ncurses-dev 时,它似乎为Python2 安装,但当我尝试为Python3 运行我的脚本时,它显示。

ImportError: No module named curses

您如何让ncursesPython3 工作?

【问题讨论】:

    标签: python python-3.x ncurses python-curses


    【解决方案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?
    • 我使用的是 Ubuntu 14.04.3 LTS
    • 这里有什么吗:/usr/lib/python3.4/curses?
    • 我只是试着输入你所做的,当我做“导入诅咒”时,它说没有名为“_curses”的模块。是的,我里面确实有东西。虽然很奇怪我在那里有一个 python3 和 python3.4 文件夹。
    • 我想我找到了问题... Python 自动运行 3.5,所以它没有在 3.4 中选择 curses 库。我不知道如何在 3.4 中将其修复为默认值,但我可以运行“python3.4 main.py”来运行我的脚本。
    【解决方案2】:

    我遇到了同样的问题。问题是我的 Ubuntu 安装上没有安装 ncurses。为了修复它,我跑了:

    sudo apt-get install libncurses-dev
    

    然后重新安装 Python。在我的情况下:

    pyenv install 3.8.1
    

    当询问 是否继续安装时回答 y? (是/否)

    这解决了问题。

    【讨论】:

      猜你喜欢
      • 2015-08-20
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-06
      • 2020-08-15
      • 1970-01-01
      相关资源
      最近更新 更多