41

我在我的 Windows 7 (x64) 机器上安装了正在运行的 Python 2.7/3.4。我想在 Windows 上测试 curses。

诅咒已安装但无法正常工作:

>>> import curses
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Tools\Python3.4.2\lib\curses\__init__.py", line 13, in <module>
    from _curses import *
ImportError: No module named '_curses'

文档说:

Windows 版本的 Python 不包含curses模块。有一个名为UniCurses的移植版本可用。

因此,Python 3.4 的 Windows 安装程序安装了未解决依赖关系的 curses。可以将其命名为错误...

好的,我研究了 UniCurses。它是PDCurses的包装器:

UniCurses 是 Python 2.x/3.x 的包装器,它在所有平台(MS Windows、Linux 和 Mac OS X)上提供了一组统一的 Curses 函数,语法接近原始 NCurses。为了在 Microsoft Windows 系统上提供 Curses 功能,它包装了 PDCurses

通过安装 UniCursespip3会导致错误:

C:\Users\Paebbels>pip3 install UniCurses
Downloading/unpacking UniCurses
  Could not find any downloads that satisfy the requirement UniCurses
  Some externally hosted files were ignored (use --allow-external UniCurses to allow).
Cleaning up...
No distributions at all found for UniCurses
Storing debug log for failure in C:\Users\Paebbels\pip\pip.log

Python 的 UniCurses 站点上的 SourceForge 链接已失效。手动搜索 SourceForge 有助于再次找到适用于 Python 的 UniCurses

但是,UniCurses 1.2 安装程序在我的 Windows 注册表中找不到任何 Python 安装。(Python 2.7.9 和 Python 3.4.2 可用)。

我还研究了公共领域诅咒(PDCurses)。PD Cureses 3.4 是从 2008 年底开始的。所以它已经 7 岁了。我不相信它适用于 Windows 7、Windows 8.1 或 Windows 10。

有什么方法可以使用 Python 在 Windows 上运行诅咒。

(Windows Python,不是 CygWin Python!)

4

3 回答 3

61

如果您为 Windows 手动安装或像其他包中的其他包一样,您可以使用 curses 跨平台(Windows、MacOS、GNU/Linux)。

  1. 安装轮组。如果您需要有关车轮的更多信息,请单击此处。

  2. 转到此存储库

  3. 使用您的 python 版本下载一个包,例如 python 3.4:

    curses-2.2-cp34-none-win_amd64.whl
    
  4. 安装它(如果适用于 Windows,则此命令在 GNU/Linux 中像其他软件包一样安装)

    python -m pip install curses-2.2-cp34-none-win32.whl
    
  5. 只需包含在您的 python 脚本中:

    import curses 
    

您可以为 python 使用 curses 包装器。在所有终端中的 Fedora 25 和使用 git bash、powershell 或 cmd 的 Windows 10 中工作。

更新:

于 2016-12-19T14:05:00.173 回答
15

现在我们可以在 python 3.7 上使用pip install windows-curses

于 2019-06-11T04:47:44.933 回答
9

你可以试试我的 unicurses 镜像,其中包括 pdcurses dll。我目前使用 python 3.5.0 在 Windows 7 上启动并运行它。

要快速测试它是否适合您,只需克隆存储库并在其顶级目录中创建并运行一个 python 脚本,其中包含类似

from unicurses import *
stdscr = initscr()
addstr("hello world")
getch()
于 2015-12-23T15:26:50.537 回答