poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Poetry 2.1.0 and 2.1.1 pick not-really-installed WindowsApps python on Windows 11

Open chmielcode opened this issue 1 year ago • 7 comments

Description

After installing poetry 2.1.x I cannot run commands like "poetry env use ..." or "poetry new ...". I do not have a working "python" in PATH so WindowsApps version is used - it just opens Windows Store when called directly. For reasons I have the "py" Windows launcher working, but no real "python" command in PATH.

Apparently before 2.1.x Poetry used the environment that it was installed to to do Poetry things and it worked for me really well, so I'm reporting this as a bug.

Thank you for your work :)

Workarounds

I guess I could add some real python to PATH, but I didn't have to do that until now.

Poetry Installation Method

pip

Operating System

Windows 11

Poetry Version

Poetry (version 2.1.1)

Poetry Configuration

cache-dir = "[my_personal_path]"
data-dir = "[my_personal_path]"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = true
keyring.enabled = true
python.installation-dir = "{data-dir}\\python"
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Python Sysconfig

No response

Example pyproject.toml


Poetry Runtime Logs

INFO: Could not find files for the given pattern(s).

Stack trace:

14 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\application.py:327 in run exit_code = self._run(io)

13 ~\nosync\code\python\poetry_venv\Lib\site-packages\poetry\console\application.py:260 in _run exit_code = super()._run(io)

12 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\application.py:431 in _run exit_code = self._run_command(command, io)

11 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\application.py:473 in _run_command raise error

10 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\application.py:457 in _run_command exit_code = command.run(io)

9 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\commands\base_command.py:117 in run return self.execute(io) or 0

8 ~\nosync\code\python\poetry_venv\Lib\site-packages\cleo\commands\command.py:61 in execute return self.handle()

7 ~\nosync\code\python\poetry_venv\Lib\site-packages\poetry\console\commands\new.py:86 in handle return self._init_pyproject(

6 ~\nosync\code\python\poetry_venv\Lib\site-packages\poetry\console\commands\init.py:176 in _init_pyproject + Python.get_preferred_python(config, self.io).minor_version.to_string()

5 ~\nosync\code\python\poetry_venv\Lib\site-packages\poetry\utils\env\python\manager.py:277 in get_preferred_python f"Found: {active_python.executable}", verbosity=Verbosity.VERBOSE

4 ~\nosync\code\python\poetry_venv\Lib\site-packages\poetry\utils\env\python\manager.py:171 in executable return cast(Path, self._python.interpreter)

3 ~\nosync\code\python\poetry_venv\Lib\site-packages\findpython\python.py:80 in interpreter self._interpreter = Path(self._get_interpreter())

2 ~\nosync\code\python\poetry_venv\Lib\site-packages\findpython\python.py:217 in _get_interpreter return _run_script(str(self.executable), script).strip()

1 ~\nosync\code\python\poetry_venv\Lib\site-packages\findpython\python.py:23 in _run_script return subprocess.run(

CalledProcessError

Command '['C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.EXE', '-EsSc', 'import sys; print(sys.executable)']' returned non-zero exit status 9009.

at ~\AppData\Local\Programs\Python\Python313\Lib\subprocess.py:579 in run 575│ # We don't call process.wait() as .exit does that for us. 576│ raise 577│ retcode = process.poll() 578│ if check and retcode: → 579│ raise CalledProcessError(retcode, process.args, 580│ output=stdout, stderr=stderr) 581│ return CompletedProcess(process.args, retcode, stdout, stderr) 582│ 583│

chmielcode avatar Feb 24 '25 16:02 chmielcode

Hey @chmielcode,

thanks a lot for reporting this. We will have to take a closer look into this.

Until this is fixed setting virtualenvs.use-poetry-python to true should "solve" your problem for the moment. (https://python-poetry.org/docs/configuration/#virtualenvsuse-poetry-python)

fin swimmer

finswimmer avatar Feb 24 '25 16:02 finswimmer

I experience the same issue like @chmielcode. I follow the same style: no python in PATH instead using py as the windows bootstrapper.

I installed my python versions, e.g. at C:\tools\python\python313\python.exe with poetry env use C:\tools\python\python313\python.exe I get the same errors as reported at the opening post. I have multiple versions of python in the tools folder.

virtualenvs.use-poetry-python did the trick for now, thanks! But I still would appreciate a fix to use external python.exe.

best


Stack Trace: PS D:\workspace\devOps\test2\myproject> poetry env use -vvv C:\tools\Python\Python313\python.exe Loading configuration file C:\Users\User\AppData\Roaming\pypoetry\config.toml Loading configuration file C:\Users\User\AppData\Roaming\pypoetry\auth.toml [findpython:findpython] Running script: ['C:\Users\User\AppData\Local\Microsoft\WindowsApps\python.EXE', '-EsSc', 'import sys; print(sys.executable)']

Stack trace:

16 C:\tools\poetry\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

15 C:\tools\poetry\venv\Lib\site-packages\poetry\console\application.py:260 in _run 258│ with directory(self._working_directory): 259│ try: → 260│ exit_code = super()._run(io) 261│ except PoetryRuntimeError as e: 262│ io.write_error_line("")

14 C:\tools\poetry\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│

13 C:\tools\poetry\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

12 C:\tools\poetry\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

11 C:\tools\poetry\venv\Lib\site-packages\cleo\commands\base_command.py:117 in run 115│ io.input.validate() 116│ → 117│ return self.execute(io) or 0 118│ 119│ def merge_application_definition(self, merge_args: bool = True) -> None:

10 C:\tools\poetry\venv\Lib\site-packages\cleo\commands\command.py:61 in execute 59│ 60│ try: → 61│ return self.handle() 62│ except KeyboardInterrupt: 63│ return 1

9 C:\tools\poetry\venv\Lib\site-packages\poetry\console\commands\env\use.py:33 in handle 31│ return 0 32│ → 33│ env = manager.activate(self.argument("python")) 34│ 35│ self.line(f"Using virtualenv: {env.path}")

8 C:\tools\poetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:135 in activate 133│ create = True 134│ → 135│ self.create_venv(python=python_instance, force=create) 136│ 137│ return self.get(reload=True)

7 C:\tools\poetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:381 in create_venv 379│ 380│ cwd = self._poetry.file.path.parent → 381│ env = self.get(reload=True) 382│ 383│ if not env.is_sane():

6 C:\tools\poetry\venv\Lib\site-packages\poetry\utils\env\env_manager.py:234 in get 232│ if python_minor is None: 233│ # we only need to discover python version in this case → 234│ python = Python.get_preferred_python( 235│ config=self._poetry.config, io=self._io 236│ )

5 C:\tools\poetry\venv\Lib\site-packages\poetry\utils\env\python\manager.py:277 in get_preferred_python 275│ ): 276│ io.write_error_line( → 277│ f"Found: {active_python.executable}", verbosity=Verbosity.VERBOSE 278│ ) 279│ return active_python

4 C:\tools\poetry\venv\Lib\site-packages\poetry\utils\env\python\manager.py:171 in executable 169│ @property 170│ def executable(self) -> Path: → 171│ return cast(Path, self._python.interpreter) 172│ 173│ @property

3 C:\tools\poetry\venv\Lib\site-packages\findpython\python.py:80 in interpreter 78│ def interpreter(self) -> Path: 79│ if self._interpreter is None: → 80│ self._interpreter = Path(self._get_interpreter()) 81│ return self._interpreter 82│

2 C:\tools\poetry\venv\Lib\site-packages\findpython\python.py:217 in _get_interpreter 215│ def _get_interpreter(self) -> str: 216│ script = "import sys; print(sys.executable)" → 217│ return _run_script(str(self.executable), script).strip() 218│ 219│ def lt(self, other: PythonVersion) -> bool:

1 C:\tools\poetry\venv\Lib\site-packages\findpython\python.py:23 in _run_script 21│ command = [executable, "-EsSc", script] 22│ logger.debug("Running script: %s", command) → 23│ return subprocess.run( 24│ command, 25│ stdout=subprocess.PIPE,

CalledProcessError

Command '['C:\Users\User\AppData\Local\Microsoft\WindowsApps\python.EXE', '-EsSc', 'import sys; print(sys.executable)']' returned non-zero exit status 9009.

at C:\tools\Python\Python313\Lib\subprocess.py:577 in run 573│ # We don't call process.wait() as .exit does that for us. 574│ raise 575│ retcode = process.poll() 576│ if check and retcode: → 577│ raise CalledProcessError(retcode, process.args, 578│ output=stdout, stderr=stderr) 579│ return CompletedProcess(process.args, retcode, stdout, stderr) 580│ 581│

csyben avatar Feb 25 '25 19:02 csyben

Can you please provide the output of this command?

C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.EXE -EsSc 'import sys; print(sys.executable)'

It looks like findpython cannot run this to find the executable path.

abn avatar Feb 25 '25 23:02 abn

Can you please provide the output of this command?

C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.EXE -EsSc 'import sys; print(sys.executable)'

It looks like findpython cannot run this to find the executable path.

Translated from my language that would be: Python not found; Run without arguments to install

And if you run this python.EXE without arguments it opens Microsoft Store.

chmielcode avatar Feb 28 '25 16:02 chmielcode

Hi, I am currently also experiencing this on a fresh installation of poetry 2.1.1 on Windows 11 24H2

Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
Retrieving Poetry metadata

# Welcome to Poetry!

This will download and install the latest version of Poetry,
a dependency and package manager for Python.

It will add the `poetry` command to Poetry's bin directory, located at:

C:\Users\<user>\AppData\Roaming\Python\Scripts

You can uninstall at any time by executing this script with the --uninstall option,
and these changes will be reverted.

Installing Poetry (2.1.1)
Installing Poetry (2.1.1): Creating environment
Installing Poetry (2.1.1): Installing Poetry
Installing Poetry (2.1.1): Creating script
Installing Poetry (2.1.1): Done

Poetry (2.1.1) is installed now. Great!

You can test that everything is set up by executing:

`poetry --version`

PS > poetry env list

Command '['C:\\Users\\<user>\\AppData\\Local\\Microsoft\\WindowsApps\\python.EXE', '-EsSc', 'import sys; print(sys.executable)']' returned non-zero exit status 9009.

I do have python installed (as py) and its entry in the PATH environment variables is indeed above the Windows Stub

Tkaixiang avatar Mar 13 '25 15:03 Tkaixiang

virtualenvs.use-poetry-python did the trick for now, thanks! But I still would appreciate a fix to use external python.exe.

I can confirm that this is a workaround for now

Tkaixiang avatar Mar 13 '25 15:03 Tkaixiang

Workaround in one command:

poetry config virtualenvs.use-poetry-python true

jamesdbrock avatar May 15 '25 11:05 jamesdbrock