python-poetry / install.python-poetry.org

The official Poetry installation script
https://install.python-poetry.org
205 stars 54 forks source link

[Doc] Add PowerShell snippet in the installation instructions (web & scripts) to allow Windows users to modify `%PATH%` easier #66

Open tats-u opened 2 years ago

tats-u commented 2 years ago

Issue

https://python-poetry.org/docs/master/#installing-with-the-official-installer

Add Poetry to your PATH

The installer creates a poetry wrapper in a well-known, platform-specific directory:

  • $HOME/.local/bin on Unix.
  • %APPDATA%\Python\Scripts on Windows.

If this directory is not present in your $PATH, you can add it in order to invoke Poetry as poetry.

Alternatively, the full path to the poetry binary can always be used:

  • $POETRY_HOME/bin/poetry if $POETRY_HOME is set.
  • ~/Library/Application Support/pypoetry/bin/poetry on MacOS.
  • ~/.local/share/pypoetry/bin/poetry on Linux/Unix.
  • %APPDATA%\pypoetry\Scripts\poetry on Windows.

The following snippet is helpful and should be appended in the document for Windows users:

if (-not (Get-Command poetry -ErrorAction Ignore)) { [Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";$env:APPDATA\Python\Scripts", "User") }

or (for PowerShell 6+)

if (-not (Get-Command poetry -ErrorAction Ignore)) { echo 'if (-not (Get-Command poetry -ErrorAction Ignore)) { $env:Path += ";$env:APPDATA\Python\Scripts" }' | Out-File -Append $PROFILE }

P.S. The script provided by https://install.python-poetry.org also needs this fix.

johnthagen commented 2 years ago

Related question:

tats-u commented 2 years ago

@johnthagen I have just installed Poetry to another machine, and I found that your question is also problematic.

johnthagen commented 2 years ago

On Linux, a similar snippet is provided in the new installer to help the user add poetry to the PATH:

$ sudo apt install curl python3-venv
$ curl -sSL https://install.python-poetry.org | python3 -
...
Add `export PATH="/home/user/.local/bin:$PATH"` to your shell configuration file.