46

I've had a million and one issues with Poetry recently.

I got it fully installed and working yesterday, but after a restart of my machine I'm back to having issues with it ;(

Is there anyway to have Poetry consistently recognised in my Terminal, even after reboot?


System Specs:

  • Windows 10,
  • Visual Studio Code,
  • Bash - WSL Ubuntu CLI,
  • Python 3.8.

Terminal:

me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
poetry: command not found
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3
Retrieving Poetry metadata

This installer is deprecated. Poetry versions installed using this script will not be able to use 'self update' command to upgrade to 1.2.0a1 or later.
Latest version already installed.
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ poetry run python3 cli.py
poetry: command not found
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/src$ 

Please let me know if there is anything else I can add to post to help further clarify.

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
StressedBoi69420
  • 1,376
  • 1
  • 12
  • 40

13 Answers13

68

Since this is the top StackOverflow result for "poetry command not found"...

For Mac users, create a .zshrc file in your home folder with the following:

export PATH="$HOME/.local/bin:$PATH"
Patrick Yan
  • 2,338
  • 5
  • 25
  • 33
  • 4
    You saved my life. For some reason, even after installing poetry via the recommended method, I do not have a ~/.poetry/bin directory at all. It turns out the executables are located in ~/.local/bin – Solomon Sep 10 '22 at 21:43
  • This solution is working with Poetry version 1.3.2 on MacOS 13.0 – Sameen Feb 21 '23 at 16:46
  • You might find a .zprofile file in your home folder on newer macs (I am running a M2 pro on 13.0) which you can add this line to instead. Remember the files will be hidden and you can unhide with Command+Shift+Dot – Harry Munro Apr 10 '23 at 08:43
  • You might want to update the terminal to reflect the changes: restart the terminal or run the command "source ~/.zshrc" – Peter Nijhuis May 20 '23 at 13:29
  • The same worked for me on Ubuntu 22.04.2 LTS, whereas export PATH="$HOME/.poetry/bin:$PATH" didn't help – dinarkino May 25 '23 at 12:02
  • this answer doesn't address the question, which is for Windows 10. good info, but shouldn't be the top comment. – beep_check Aug 03 '23 at 20:07
33

When I run this, after shutdown of bash Terminal:

export PATH="$HOME/.poetry/bin:$PATH"

poetry command is then recognised.

However, this isn't enough alone; as every time I shutdown the terminal I need to run the export.

Possibly needs to be saved in a file.

StressedBoi69420
  • 1,376
  • 1
  • 12
  • 40
  • Thank you, it worked but I have to run it every time I want to do `poetry shell`, is there a way around that? – Boshra Jaber Sep 13 '22 at 09:24
  • 8
    This answer should be updated with `export PATH="$HOME/.local/bin:$PATH"` on Unix, according to the [documentation](https://python-poetry.org/docs/). Best is to write this in `.bashrc` or `.zshrc`. – mattiatantardini Dec 20 '22 at 11:52
15

I updated poetry to v1.2.2 (Nov 2022), but had issues with the path being set properly. This was the path definition I found:

Windows 10:
C:\User\<myUserName>\AppData\Roaming\pypoetry\venv\Scripts

Add it temporarily to your path with:
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\pypoetry\venv\Scripts

Or set this in your usual Windows Environment setup

RexBarker
  • 1,456
  • 16
  • 14
10

To follow-up on @StressedBoi69420's answer, could you add the line he suggested, i.e. export PATH="$HOME/.poetry/bin:$PATH" to your .bashrc?

As per this other Stack Overflow post What is the default install path for poetry and @arshbot's answer, I have added the line export PATH=$PATH:$HOME/.poetry/bin to my .zshrc and it seems to be working.

julien ergan
  • 109
  • 1
  • 5
8

in Windows 11, after long and painful experiments with powershell and reading the poetry installation documentation, I solved the problem like this:

  1. installed poetry with the command:
    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

When the system reported that poetry was successfully installed and for poetry you need to register the path to the folder where it was installed. typing the poetry --version command there was an error in powershell that poetry is unknown, I could not register path through the command line.

  1. through the windows folder window settings, I made the hidden folders and files visible and went to where poetry was installed: C:\Users\user\AppData\Roaming\Python\Scripts.

  2. In order for python to see the path to poetry, I copied poetry.exe from the spot C:\Users\user\AppData\Roaming\Python\Scripts in the python work environment at: C:\Users\user\AppData\Local\Programs\Python\Python310\Scripts this way.

Pip also lies in Local. The problem was solved and the command in powershell poetry --version showed the poetry version. I hope this will help you!

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 3
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 04 '23 at 22:29
  • Just to add - if you are not able to find the path use the command ''where python'' in your command terminal. Paste the poetry.exe in the same path – Raghu May 31 '23 at 12:06
  • This is the way – John Jul 26 '23 at 09:01
7

After installation - To add poetry to your shell script in Mac add following commands in terminal

open ~/.zshrc

If zshrc file is not created previously then create it using the following commands -

The .zshrc file is not present by default in macOS Catalina, we need to create it.

Steps for creation:

  1. Open Terminal
  2. Type touch ~/.zshrc to create the respective file. (touch command will create the .zshrc in your current directory but it will be hidden)
  3. Hit Return

To open the zshrc file

  1. Open Terminal > and type: open ~/.zshrc

    In the .zshrc file add the line -

export PATH="$HOME/.local/bin:{$PATH}”

Once you have added the above command to the .zshrc file, go back to the terminal and refresh the terminal by -

source ~/.zshrc

Then execute the following in terminal

poetry --version

If you get the version name then you are ready to use!

Additionally you can refer the https://python-poetry.org/docs/#installation for further information during installation in other operating system environments.

Dilip H
  • 116
  • 1
  • 3
  • Thank you for the extensive answer, this solved the problem in your export command the ending " is the wrong symbol I think, I get an error when I tried to copy it directly. – Code_beginner Jun 27 '23 at 13:37
5

For windows (on powershell) try this please:

$Env:Path += ";C:\Users\YourUserName\AppData\Roaming\Python\Scripts"; setx PATH "$Env:Path"

(from the page https://www.jetbrains.com/help/pycharm/poetry.html#c2dbb15c)

mears
  • 359
  • 4
  • 13
  • if your path is already long (more than 1024 characters) be very careful on running this command because it will truncate and only preserve the first 1024 characters from your path and can potentially leave you with a broken pc – Theo May 10 '23 at 22:03
  • @Theo and what would be the solution then? – alex Jul 07 '23 at 22:06
  • 1
    one is to manually add the environment variable from the windows UI – Theo Jul 10 '23 at 04:49
3

Just to add some beginner level context around Julien's excellent answer, to find and edit your .zshrc file, you need to use your default editor (in this case i am using VSCode) and run:

>> code ~/.zshrc

...and, crucially, restart the terminal.

More details and the source of this info here: https://superuser.com/questions/886132/where-is-the-zshrc-file-on-mac

atomscale
  • 111
  • 1
  • 5
1

After installation of Poetry you gotin output command line the tips:

  • Add export PATH="/Users/USERNAME/.local/bin:$PATH" to your shell configuration file.

  • Alternatively, you can call Poetry explicitly with /Users/USERNAME/.local/bin/poetry.

ps: I've installed it in MacOS using curl.

abdoulsn
  • 842
  • 2
  • 16
  • 32
0

Generally the path of Poetry should be added to the ENV variable PATH.

1. use which find where is poetry installed just after you installed poetry.

which poetry

# $HOME/.local/bin/poetry  # if installed with Brew
# maybe elsewhere: "$HOME/.poetry/bin:$PATH"

In fact, it reminds users to add the path to the shell configuration file in the output of the Poetry installation.

Installing Poetry (1.2.2): Done

Poetry (1.2.2) is installed now. Great!

To get started you need Poetry's bin directory (/home/shell/.local/bin) in your PATH environment variable.

Add export PATH="/home/shell/.local/bin:$PATH" to your shell configuration file.

Alternatively, you can call Poetry explicitly with /home/shell/.local/bin/poetry.

2. find what kind of shell you are using:

echo $SHELL

# /usr/bin/zsh    # many people use zsh or oh-my-zsh
  # For zsh, put stuff in ~/.zshrc, which is always executed.
  # For bash, put stuff in ~/.bashrc, and make ~/.bash_profile source it.

3. add the Poetry executable path to $PATH and add it to a shell startup configuration file to init it every time you start with that shell:

export SHELL_RCFILE="~/.zshrc"
echo "export POETRY_PATH=$HOME/.local/bin/ && export PATH="$POETRY_PATH:$PATH" >> $SHELL_RCFILE

Reference: zsh, bash startup files loading

Haili Sun
  • 621
  • 8
  • 13
0

In Windows 10 using WSL2, after running

curl -sSL https://install.python-poetry.org | python3 -

enter image description here

That essentially tells to run

export PATH="/home/tperes/.local/bin:$PATH"

After, when running poetry --version will get

enter image description here

Tiago Martins Peres
  • 14,289
  • 18
  • 86
  • 145
0

MacOS:

  1. curl -sSL https://install.python-poetry.org | python3 -
  2. touch ~/.zshrc
  3. open ~/.zshrc
  4. In ~/.zshrc: export PATH="/Users/YOURUSERNAME/.local/bin:$PATH"
  5. Save the file: cmd+S
  6. Check the command: poetry --version
Angielf
  • 11
0

For windows you install curl with chocolatey by running the following command:

choco install curl

after installation is complete run the following command to install poetry.

curl -sSL https://install.python-poetry.org | python3 -

OutPut

Poetry (1.5.1) is installed now. Great!

To get started you need Poetry's bin directory (C:\Users\<user>\AppData\Roaming\Python\Scripts) in your `PATH`
environment variable.

Alternatively, you can call Poetry explicitly with `C:\Users\<user>\AppData\Roaming\Python\Scripts\poetry`.

You can test that everything is set up by executing:

poetry --version

Add poetry's bin directory (C:\Users<user>\AppData\Roaming\Python\Scripts) in your PATH environment variable.

Check if poetry works poetry --version

Philip Mutua
  • 6,016
  • 12
  • 41
  • 84