python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.6k stars 2.26k forks source link

Poetry fails to find Git on Windows 10 #7320

Open mrlegohead0x45 opened 1 year ago

mrlegohead0x45 commented 1 year ago
powershell> poetry new pygame-test -vvv

  Stack trace:

  9  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

  8  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│

  7  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│

  6  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

  5  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

  4  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:

  3  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

  2  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\console\commands\new.py:66 in handle
       64│         readme_format = self.option("readme") or "md"
       65│
    →  66│         config = GitConfig()
       67│         author = None
       68│         if config.get("user.name"):

  1  AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\core\vcs\git.py:199 in __init__
      197│         try:
      198│             config_list = subprocess.check_output(
    → 199│                 [executable(), "config", "-l"], stderr=subprocess.STDOUT
      200│             ).decode()
      201│

  RuntimeError

  Unable to find a valid git executable

  at AppData\Roaming\pypoetry\venv\lib\site-packages\poetry\core\vcs\git.py:182 in executable
      178│     else:
      179│         _executable = "git"
      180│
      181│     if _executable is None:
    → 182│         raise RuntimeError("Unable to find a valid git executable")
      183│
      184│     return _executable
      185│
      186│
powershell> git --version
git version 2.34.1.windows.1

Issue

Trying to create a new poetry project on windows 10 fails saying it hasn't found git. I recently updated poetry from 1.1.13 to 1.3.1 by running poetry self update and copying ~\AppData\Roaming\pypoetry\venv\Scripts\poetry.exe to ~\AppData\Roaming\Python\Scripts\poetry.exe as suggested in #5377. That worked. Then trying to create a new project via poetry new, poetry complains that it hasn't found a valid git executable, when git is in PATH, looking at the source code it trys to run %WINDIR%\\System32\\where.exe git, running this command in cmd finds git successfully. Maybe poetry requires a newer version of git than 2.34 which I have, seeing that the latest is 2.39?

neersighted commented 1 year ago

Poetry shouldn't require a Git executable on Windows since we use Dulwich now. Can you please post the output of poetry config?

mrlegohead0x45 commented 1 year ago
powershell> poetry config --list
cache-dir = "C:\\Users\\mrlegohead\\AppData\\Local\\pypoetry\\Cache"
experimental.new-installer = true
experimental.system-git-client = false
installer.max-workers = null
installer.no-binary = null
installer.parallel = true
repositories.pypi_test.url = "https://test.pypi.org/legacy/"
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\mrlegohead\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
Secrus commented 1 year ago

I would suggest you uninstall Poetry all together and reinstall it. My guess would be that something went wrong with 1.1.13 -> 1.3.1 migration and files got mixed up or something

tonybarbieri commented 1 year ago

@neersighted @Secrus I am hitting the same issue using a fresh install of poetry 1.4.0. I am on Windows using Powershell. I installed git and python using scoop. Running 'poetry new' I get the same stack trace as above.

LexSong commented 1 year ago

check https://github.com/python-poetry/poetry/issues/5420

It seems that if the git.exe is in the sub-directory of the current folder will have this issue. A temporary workaround is create a new folder and run poetry new in it.