python-poetry / python-poetry/poetry

[WinError 193] when `virtualenvs.prefer-active-python` is `true`

Open
#8,229 9 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/venv area/windows kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

  • 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.

Due to #8160 I can't install the latest stable version via the command in the document.

Issue

I got

[WinError 193] %1 is not a valid Win32 application.

with virtualenvs.prefer-active-python set to true. There may be a related thread #7075.

I use pyenv to manage my Python version. To use the different Python version from the version used to install poetry, I enable virtualenvs.prefer-active-python following the document.

poetry config virtualenvs.prefer-active-python true

My current Python versions are

pyenv global: 3.12.0b4
pyenv local: 3.10.11

However poetry doesn't use 3.10.11. Here is the output of poetry debug info -vvv


Poetry
Loading configuration file C:\Users\Ivana\AppData\Roaming\pypoetry\config.toml
Version: 1.6.0.dev0
Python:  3.12.0

  Stack trace:

  18  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:327 in run
       325│
       326│             try:
     → 327│                 exit_code = self._run(io)
       328│             except BrokenPipeError:
       329│                 # If we are piped to another process, it may close early and send a

  17  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\application.py:190 in _run
       188│         self._load_plugins(io)
       189│
     → 190│         exit_code: int = super()._run(io)
       191│         return exit_code
       192│

  16  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:431 in _run
       429│             io.input.interactive(interactive)
       430│
     → 431│         exit_code = self._run_command(command, io)
       432│         self._running_command = None
       433│

  15  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:473 in _run_command
       471│
       472│         if error is not None:
     → 473│             raise error
       474│
       475│         return terminate_event.exit_code

  14  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\application.py:457 in _run_command
       455│
       456│             if command_event.command_should_run():
     → 457│                 exit_code = command.run(io)
       458│             else:
       459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  13  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\base_command.py:119 in run
       117│         io.input.validate()
       118│
     → 119│         status_code = self.execute(io)
       120│
       121│         if status_code is None:

  12  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\command.py:62 in execute
        60│
        61│         try:
     →  62│             return self.handle()
        63│         except KeyboardInterrupt:
        64│             return 1

  11  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\commands\debug\info.py:27 in handle
        25│         command = self.get_application().get("env info")
        26│
     →  27│         exit_code: int = command.run(self.io)
        28│         return exit_code
        29│

  10  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\base_command.py:119 in run
       117│         io.input.validate()
       118│
     → 119│         status_code = self.execute(io)
       120│
       121│         if status_code is None:

   9  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\cleo\commands\command.py:62 in execute
        60│
        61│         try:
     →  62│             return self.handle()
        63│         except KeyboardInterrupt:
        64│             return 1

   8  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\console\commands\env\info.py:28 in handle
        26│         from poetry.utils.env import EnvManager
        27│
     →  28│         env = EnvManager(self.poetry).get()
        29│
        30│         if self.option("path"):

   7  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:236 in get
       234│             "virtualenvs.prefer-active-python"
       235│         )
     → 236│         python_minor = self.get_python_version(
       237│             precision=2, prefer_active_python=prefer_active_python, io=self._io
       238│         ).to_string()

   6  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:108 in get_python_version
       106│
       107│         if prefer_active_python:
     → 108│             executable = EnvManager._detect_active_python(io)
       109│
       110│             if executable:

   5  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:86 in _detect_active_python
        84│         )
        85│
     →  86│         executable = EnvManager._full_python_path("python")
        87│
        88│         if executable is not None:

   4  ~\AppData\Roaming\pypoetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:69 in _full_python_path
        67│
        68│         try:
     →  69│             executable = subprocess.check_output(
        70│                 [path_python, "-c", "import sys; print(sys.executable)"], text=True
        71│             ).strip()

   3  ~\.pyenv\pyenv-win\versions\3.12.0b4\Lib\subprocess.py:466 in check_output
        464│         kwargs['input'] = empty
        465│
     →  466│     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
        467│                **kwargs).stdout
        468│

   2  ~\.pyenv\pyenv-win\versions\3.12.0b4\Lib\subprocess.py:548 in run
        546│         kwargs['stderr'] = PIPE
        547│
     →  548│     with Popen(*popenargs, **kwargs) as process:
        549│         try:
        550│             stdout, stderr = process.communicate(input, timeout=timeout)

   1  ~\.pyenv\pyenv-win\versions\3.12.0b4\Lib\subprocess.py:1026 in __init__
       1024│                             encoding=encoding, errors=errors)
       1025│
     → 1026│             self._execute_child(args, executable, preexec_fn, close_fds,
       1027│                                 pass_fds, cwd, env,
       1028│                                 startupinfo, creationflags, shell,

  OSError

  [WinError 193] %1 不是有效的 Win32 應用程式。

  at ~\.pyenv\pyenv-win\versions\3.12.0b4\Lib\subprocess.py:1538 in _execute_child
      1534│             sys.audit("subprocess.Popen", executable, args, cwd, env)
      1535│
      1536│             # Start the process
      1537│             try:
    → 1538│                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
      1539│                                          # no special security
      1540│                                          None, None,
      1541│                                          int(not close_fds),
      1542│                                          creationflags,

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read poetry/utils/env/env_manager.py, especially the _detect_active_python and _full_python_path entry points shown in the traceback. Reproduce the failure on Windows with pyenv-win, Python 3.12.0b4 as the global version, Python 3.10.11 as the local version, and virtualenvs.prefer-active-python enabled. Done means Poetry selects the local Python without raising WinError 193.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.