Search code examples
pythonpython-3.xpython-poetry

POETRY_HOME doesnt exist - python poetry / cant get poetry to work


I am trying to install python poetry on a windows device. I do not want it installed in /Users because if the user leaves, this directory will be defunct, and mess up the entire server.

I have so far installed on my user by downloading the install-poetry.py and running it as a python script i.e. python install-poetry.py. This installed in my user directory as expected and poetry worked.

I have ctrl+X and moved the entire pypoetry folder from %APPDATA%\pypoetry to C:/Program Files, and the poetry.sym from Users/%APPDATA%/Python312/Scripts to the C:/Program Files/Python312/Scripts folder

I have then added all combinations to the environment variable PATH including:

  • C:\Program Files\Python312\Scripts
  • C:\Program Files\Python312\Scripts\
  • C:\Program Files\pypoetry
  • C:\Program Files\pypoetry\venv\Scripts\
  • C:\Program Files\pypoetry\venv\Scripts
  • C:\Program Files\pypoetry\venv\Scripts\poetry

But none of the above work.

The machine cannot use "Invoke Web-Request" as it cannot contact the internet, and I am not sure how to modify this installation command (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py - to refer to my install-poetry.py file in powershell.

Furthermore, when I try to use cmd command:

  • curl -sSL https://install.python-poetry.org | POETRY_HOME=/etc/poetry python3 -
  • curl -sSL D:/Software/install-poetry.py | POETRY_HOME=C:\Program Files\pypoetry\venv\Scripts\poetry python3 -

I get the error POETRY_HOME : The term 'POETRY_HOME' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

It is worth noting I do not fully undersand systems and PATHS.

I also tried adding POETRY_HOME as a system variable to C:\Program Files\pypoetry\venv\Scripts\poetry.exe but resulted in the same error.

Please can someone advise?


Solution

  • Note that you'll probably have better luck using a Python virtual environment:

    1. cd into your actual project dir, then
    2. python -m venv venv,
    3. venv\Scripts\activate,
    4. python -m pip install poetry,
    5. done.

    poetry now works for as long as your virtual environment is active, working exclusively within the confines of that environment: nothing's tied to a specific user's home directory. Instead, everything is nice and contained, ready for when you need it.

    And note that the environment doesn't care "which dir you're in" when you activate or deactivate it, just call the appropriate script (since you're in Windows, that's the Scripts\activate and Scripts\deactivate commands in the virtual environment dir itself).

    Also note that if you use python 3.11 or above, that's pretty much your only option, Python will now yell at you if you don't use virtual environments because they solve so many env-related problems.