Skip to content

magic conda fails in windows (re can not parse path) #14350

@gnosys-scrawford

Description

@gnosys-scrawford

In a jupyter notebook when trying to run conda or mamba as a magic command, in Windows, it fails. For example
%conda --version

The problem is that in IPython\core\magics\packaging.py, in _get_conda_like_executable there is

    match = re.search(
        rf"^#\s*cmd:\s*(?P<command>.*{executable})\s[create|install]",
        history,
        flags=re.MULTILINE,
    )

where executable is a Path object. In windows, this gets converted to a string with backslashes. re then tries to treat these backslashes as escape characters and fails. For example, when executable is 'c:\Users\me\mambaforge\envs\myenv\conda' the error will be error: incomplete escape \U at position 28

I believe the fix is to use executable.name instead of executable in the search string. This will emulate previous versions but I don't know if there are other considerations.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions