Skip to content

utils.env._full_python_path output encoding on Windows #7313

@Winand

Description

@Winand
  • Poetry version: 1.3.1
  • Python version: 3.9.13
  • OS version and name: Windows 11 22H2
  • pyproject.toml: gist
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

I want to use poetry along with pyenv-win.
When I set prefer-active-python = true and call poetry install I get "Command cannot be found" error:

PS F:\python\projects\tutorial-hypermodern-python-winand> poetry install
El sistema no puede encontrar la ruta especificada.

Command 'C:\Users\Àíäðåé\.pyenv\pyenv-win\versions\3.8.10\python.exe -c "import sys; print('.'.join([str(s) for s in sys.version_info[:3]]))"' returned non-zero exit status 1.

Username in the output has broken encoding (Àíäðåé instead of Андрей). I've found out that poetry tries to get current interpreter using utils.env._full_python_path function which returns broken path in my case.

I've found two possible solutions:

  • Add universal_newlines=True / text=True to subprocess.check_output call. That fixes only paths which can be encoded with local encoding - cp1251.
  • Encode output to UTF-8 in child process:
subprocess.check_output(
    list_to_shell_command(
        # [python, "-c", '"import sys; print(sys.executable)"']
        [python, "-c", '"import sys; sys.stdout.buffer.write(sys.executable.encode())"']
    ),
    shell=True,
).strip()

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions