【问题标题】:ImportError: No module named '_curses' when trying to import blessingsImportError:尝试导入祝福时没有名为“_curses”的模块
【发布时间】:2016-06-21 09:27:34
【问题描述】:

我正在尝试运行这个:

from blessings import Terminal

t = Terminal()

print (t.bold('Hi there!'))
print (t.bold_red_on_bright_green('It hurts my eyes!'))

with t.location(0, t.height - 1):
    print ('This is at the bottom.')

这里的第一个例子是:https://pypi.python.org/pypi/blessings

但是,我收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\�����\AppData\Local\Programs\Python\Python35-     32\lib\site-packages\blessings\__init__.py", line 5, in <module>
    import curses
  File "C:\Users\�����\AppData\Local\Programs\Python\Python35-32\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ImportError: No module named '_curses'

我的系统是win10 x64。

【问题讨论】:

  • 试试这个curses Windows 实现。
  • 我在 Windows 7 上遇到了同样的问题,正在寻找解决方法。自述文件中提到 colorama 在 Windows 上使用的部分意味着该库以某种方式在 Windows 上工作。我对 Python 有点陌生,所以我不确定将 import 语句包装在 try/except 构造中是否是一种有效的方法,但我正在研究它。另外,仅供参考,可以确认blessings 的分支blessed 也有同样的问题(v1.6)。
  • @AdamP 更新,blessed 模块的自述文件与祝福模块的声明略有不同,它明确表明该模块在 Windows 命令提示符下不起作用:“祝福不提供... Windows 命令提示符支持。Windows 的 Python 的 PDCurses 构建目前仅提供部分支持 - 计划与 ansi 模块合并与 colorama 一起解决此问题。欢迎使用补丁!"
  • @eryksun 您如何让该实现运行?
  • 你的意思是如何安装wheel包?使用pip install curses‑2.2‑cp35‑none‑win32.whl 或您要安装的轮子的任何文件名。

标签: python windows module curses python-curses


【解决方案1】:

你只需要下载库

pip install windows-curses

【讨论】:

    【解决方案2】:

    首先像这样使用 pip 安装 curses 打开命令提示符

    键入“pip install windows-curses”(仅当 pip 安装在环境变量中时才有效)

    如果使用 Pycharm 运行 curses 不起作用,请尝试其他解释器应用程序,如 Atom、Visual Studios,如果不起作用,请在环境变量中安装 Python(链接将在底部)。然后启动 CMD 或命令提示符并输入“python(.py 文件的根目录)” (例如python C:\Users\user\Plane.py)然后按回车键。

    在环境变量中安装 Python 的链接 - https://www.youtube.com/watch?v=1jyOHCTgWpg

    【讨论】:

      【解决方案3】:

      同时 - Windows 10 上的 Python 2.7.15 - 可以通过以下方式添加对诅咒的支持:

      pip install windows-curses
      

      【讨论】:

      • 此外,这在运行 Python 3.5.3 的 Windows 10 上对我有用
      • 在运行 CPython 3.7.4 的 Windows 7 上为我工作。
      • 在控制台中工作,在 PyCharm 等大多数 IDE 中失败。
      【解决方案4】:

      这是 Windows 上的一个已知错误。它已经开放 5 年了,所以不要屏住呼吸。

      非官方的curses 构建是不够的,因为它还需要fcntl,这不太可能很快被移植。

      【讨论】:

        【解决方案5】:

        Windows 机器不支持curses 模块。来自模块文档:

        虽然 curses 在 Unix 环境中使用最广泛,但版本是 可用于 DOS、OS/2 和可能的其他系统。这 扩展模块旨在匹配 ncurses 的 API,一个 托管在 Linux 和 BSD 变体上的开源 curses 库 Unix。

        here 安装curses 的非官方Windows 二进制文件,然后重试。

        【讨论】:

        • 是不是说我不能在windows上使用祝福库?
        猜你喜欢
        • 2014-12-09
        • 2019-01-05
        • 1970-01-01
        • 2018-02-08
        • 2021-06-09
        • 2019-01-22
        • 1970-01-01
        • 2021-10-18
        • 1970-01-01
        相关资源
        最近更新 更多