Poetry installed but `poetry: command not found`

Question:

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.

Asked By: StressedBoi69420

||

Answers:

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.

Answered By: StressedBoi69420

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.

Answered By: julien ergan

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

Answered By: atomscale

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"
Answered By: Patrick Yan

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

Answered By: Haili Sun

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

Add it temporarily to your path with:
set PATH=%PATH%;%USERPROFILE%AppDataRoamingpypoetryvenvScripts

Or set this in your usual Windows Environment setup

Answered By: RexBarker

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.

Answered By: abdoulsn

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.

Answered By: Dilip H

For windows (on powershell) try this please:

$Env:Path += ";C:UsersYourUserNameAppDataRoamingPythonScripts"; setx PATH "$Env:Path"

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

Answered By: mears

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

Answered By: Tiago Martins Peres

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. 2. through the windows folder window settings, I made the hidden folders and files visible and went to where poetry was installed: C:UsersuserAppDataRoamingPythonScripts. 3. In order for python to see the path to poetry, I copied poetry.exe from the spot C:UsersuserAppDataRoamingPythonScripts in the python work environment at: C:UsersuserAppDataLocalProgramsPythonPython310Scripts 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!

Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.