Skip to content

Compilation on Linux without both libffi-dev and libncurses-dev results in an unexpected warning when using the new REPL #131189

Closed

Description

@plashchynski

Bug report

Bug description:

Compilation on Ubuntu 24.04.2 with ./configure --with-pydebug without libffi-dev package installed cause the following unexpected warning while loading the resulting executable as ./python:

warning: can't use pyrepl: No module named 'msvcrt'

After installation of libffi-dev and recompilation the warning was resolved.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Related

Activity

  1. StanFromIreland commented on Mar 13, 2025

    @StanFromIreland
    Member

    Yes, its listed as a dependency. Behavior like this is to be expected. I don't really see a need for anything to be introduced (eg warnings).

  2. plashchynski commented on Mar 13, 2025

    @plashchynski
    ContributorAuthor

    After a quick exploration, I've found that the warning caused by an ImportError exception in the following code in pyrepl:

    try:
    from .unix_console import UnixConsole as Console, _error
    except ImportError:
    from .windows_console import WindowsConsole as Console, _error

    It's unable to load unix_console because of lack of libffi-dev (and _ctypes) package cause the following import error:

      File "/home/dzmitry/cpython/Lib/_pyrepl/readline.py", line 46, in <module>
        from .unix_console import UnixConsole as Console, _error
      File "/home/dzmitry/cpython/Lib/_pyrepl/unix_console.py", line 35, in <module>
        from . import curses
      File "/home/dzmitry/cpython/Lib/_pyrepl/curses.py", line 28, in <module>
        from . import _minimal_curses as _curses  # type: ignore[no-redef]
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/home/dzmitry/cpython/Lib/_pyrepl/_minimal_curses.py", line 12, in <module>
        import ctypes
      File "/home/dzmitry/cpython/Lib/ctypes/__init__.py", line 8, in <module>
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
    

    So it fallbacks to import of windows_console on Linux, resulting in another ModuleNotFoundError that results in the No module named 'msvcrt' warning.

    In such situation, I'd expect to see a warning about lack of _ctypes. So, may we have here some platform checks instead of catching and suppressing import errors?

    try:
    from .unix_console import UnixConsole as Console, _error
    except ImportError:
    from .windows_console import WindowsConsole as Console, _error

  3. picnixz commented on Mar 13, 2025

    @picnixz
    Member

    We should warn at the make step or the configure step when libffi is not available I think.

  4. picnixz commented on Mar 13, 2025

    @picnixz
    Member

    cc @encukou WDYT is the best approach? (and how do we actually check it?) I'm actually surprised that make correctly worked here (aren't we checking the necessary dependencies?)

  5. encukou commented on Mar 13, 2025

    @encukou
    Member

    ctypes is optional; libffi is not a build requirement.
    I'm not sure anyone knows what “optional” means exactly; see the zlib discussion.

  6. picnixz commented on Mar 13, 2025

    @picnixz
    Member

    Maybe we should warn once we're done with make? like, if ctypes is not available and we're on Linux, then the new REPL won't work (maybe the old REPL could work?) Having a simple warning: can't use pyrepl: No module named 'msvcrt' doesn't really help in this case.

  7. added
    stdlibStandard Library Python modules in the Lib/ directory
    topic-replRelated to the interactive shell
    3.13only security fixes
    and removed on Mar 13, 2025
  8. 25 remaining items

  9. added a commit that references this issue on Jul 15, 2025
  10. added a commit that references this issue on Jul 15, 2025
  11. added a commit that references this issue on Aug 4, 2025
  12. jkfields commented on Aug 4, 2025

    @jkfields

    Bug report

    Bug description:

    Compilation on Ubuntu 24.04.2 with ./configure --with-pydebug without libffi-dev package installed cause the following unexpected warning while loading the resulting executable as ./python:

    warning: can't use pyrepl: No module named 'msvcrt'

    After installation of libffi-dev and recompilation the warning was resolved.

    CPython versions tested on:

    CPython main branch

    Operating systems tested on:

    Linux

    Linked PRs

    Related

    I received the same message with Python 3.13.5 on RHEL 9! I had to install ncurses-devel and readline-devel to make it go away.

  13. skirpichev commented on Aug 5, 2025

    @skirpichev
    Member

    #131201 is not backported to 3.13.

    If this is intentional, then the bugreport might be closed. @ambv?

  14. added a commit that references this issue on Aug 19, 2025
  15. chris-eibl commented on Aug 24, 2025

    @chris-eibl
    Member

    If possible, it would be nice to be backported since this frequently pops up (just recently https://discuss.python.org/t/cant-use-pyrepl-no-module-named-msvcrt-in-linux/67037/9). IDK whether #131201 qualifies for backport, though, but looks quite simple if that helps backporting :)

  16. added a commit that references this issue on Sep 9, 2025
  17. ambv commented on Sep 15, 2025

    @ambv
    Contributor

    We can't backport this to 3.13, too much of a code difference between the branches and treating this as a bug fix is a stretch (that we used for 3.14, but that's before the final release).

  18. added a commit that references this issue on Sep 15, 2025
  19. added a commit that references this issue on Sep 15, 2025
  20. added a commit that references this issue on Oct 13, 2025
  21. added a commit that references this issue on Oct 13, 2025
  22. added a commit that references this issue on Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.13only security fixes3.14bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-replRelated to the interactive shelltype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions