[Python] Deriving path of Python Scripts folder on Windows

Discussão em 'Python' iniciado por Stack, Março 5, 2025.

  1. Stack

    Stack Membro Participativo

    I installed Python 3.13 on Windows 11 with

    winget install python3 --scope machine`


    Then I installed pip with

    python -m ensurepip


    This puts pip in %APPDATA\Python\Python313\site-packages. Since this directory is in sys.path, I can run pip like this:

    python -m pip ...


    This is great: the command is easy to remember, and isn't going to change when I upgrade Python.

    However, if the package includes an executable or script, these go in %APPDATA\Python\Python313\Scripts. This is not automatically added to %PATH% by the Python installer. And since the Python version number changes, I can't just hardcode this path in batch scripts.

    I also checked site.USER_BASE but it is set to %APPDATA%\Python which doesn't include the Python version. On the other hand site.USER_SITE includes the Python version and \site-packages.

    Is there an easy way to run package scripts with Python on Windows without expecting the end user to modify %PATH%?

    Continue reading...

Compartilhe esta Página