Poetry installed but `poetry: command not found`
Asked Answered
G

21

76

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.

Gordie answered 17/11, 2021 at 11:45 Comment(2)
What is your system? How did you install it? Did you use any virtualenv / conda environment during the install?Unhandy
I used the curl command, via bash, in post. Will append system specs to postGordie
G
45

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.

Gordie answered 18/11, 2021 at 9:35 Comment(2)
Thank you, it worked but I have to run it every time I want to do poetry shell, is there a way around that?Alliterative
This answer should be updated with export PATH="$HOME/.local/bin:$PATH" on Unix, according to the documentation. Best is to write this in .bashrc or .zshrc.Consuelaconsuelo
K
112

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"
Kenner answered 9/9, 2022 at 1:47 Comment(7)
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/binBadgett
This solution is working with Poetry version 1.3.2 on MacOS 13.0Archi
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+DotMatey
You might want to update the terminal to reflect the changes: restart the terminal or run the command "source ~/.zshrc"Terbium
The same worked for me on Ubuntu 22.04.2 LTS, whereas export PATH="$HOME/.poetry/bin:$PATH" didn't helpQuintus
this answer doesn't address the question, which is for Windows 10. good info, but shouldn't be the top comment.Mayes
Still works perfectly late 2023Wayward
G
45

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.

Gordie answered 18/11, 2021 at 9:35 Comment(2)
Thank you, it worked but I have to run it every time I want to do poetry shell, is there a way around that?Alliterative
This answer should be updated with export PATH="$HOME/.local/bin:$PATH" on Unix, according to the documentation. Best is to write this in .bashrc or .zshrc.Consuelaconsuelo
F
27

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

Forensic answered 17/11, 2022 at 11:21 Comment(0)
W
15

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!

Workable answered 31/3, 2023 at 6:34 Comment(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.Malefic
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 pathLexicostatistics
After installation via the poetry installer with the PowerShell method, I cannot navigate to C:\Users\<user>\AppData\Roaming\Python\Scripts because it says that path doesn't exist. What is happening there?Chenoweth
P
12

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.

Photoemission answered 15/2, 2022 at 3:41 Comment(1)
In my case I didn't had a .zshrc file but adding it to ~/.zprofile worked. Thanks for your answerCayser
H
12

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)

Hideaway answered 1/3, 2023 at 9:5 Comment(3)
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 pcAurthur
@Aurthur and what would be the solution then?Blinders
one is to manually add the environment variable from the windows UIAurthur
K
11

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.

Kaolin answered 22/1, 2023 at 8:21 Comment(1)
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.Thereinto
P
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

Patrology answered 11/8, 2022 at 6:19 Comment(0)
S
2

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

Stratify answered 14/3, 2023 at 19:13 Comment(0)
A
2

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
Avictor answered 6/4, 2023 at 6:40 Comment(1)
Please don't repeat answers.Brothel
I
2

it helped me for Windows 10:

  1. manually change PATH variable for users. add this path: %USERPROFILE%\AppData\Roaming\pypoetry\venv\Scripts
    It's directory of poetry file. Poetry file has to be in Scripts with this path.
  2. restart PC. probably path variables set after restart. in my case it helped.
  3. now u can try poetry --version
Isogamy answered 4/10, 2023 at 13:37 Comment(0)
R
1

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

Roybn answered 20/10, 2022 at 7:23 Comment(0)
N
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.

Nady answered 14/1, 2023 at 23:0 Comment(1)
Life saver. Other answers didn't work for me. Thank you immensely.Elea
W
1

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

Witted answered 19/6, 2023 at 11:51 Comment(0)
T
1

Use thepipx installer to install Poetry, as suggested in the Poetry Docs.

To fix your PATH, simply run the follwoing command:

pipx ensurepath
Threnode answered 10/4 at 8:58 Comment(0)
J
0

If you are using zsh, just add your python path where the packages are installed to ~/.zprofile. For me, my pip location is /Library/Frameworks/Python.framework/Versions/3.8/bin/pip3. So execute the below.

vi ~/.zprofile

PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}

source ~/.zprofile

Jacky answered 15/12, 2023 at 6:55 Comment(0)
A
0

There is already a file named ".bashrc" , located in your home directory, is read-in and executed whenever a bash script or bash shell is started.

open it and add bellow line to avoid redandant task:

export PATH="$HOME/.local/bin:$PATH"
Avunculate answered 12/1 at 21:25 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Malefic
Please don't post duplicate answers.Hamby
S
0

Hello so uh my Specs is:

Windows 10

so bassically go to the docs of https://python-poetry.org/docs/#installation

and after that use

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

if you have py not python 3

then after go to environment variables

then go to your local variables then add new then set the variable name to:

variable name: Path variable path: %APPDATA%\Python\Scripts

after that use poetry --version

Syndactyl answered 16/2 at 10:13 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Malefic
F
0

Uninstall and reinstall Poetry, resolved it for me:

$ poetry
bash: poetry: command not found...
$ pip uninstall poetry
Found existing installation: poetry 1.7.1
Uninstalling poetry-1.7.1
...
$ pip install poetry
...
Successfully installed cachecontrol-0.14.0 poetry-1.8.2 poetry-core-1.9.0
$ poetry --version
Poetry (version 1.8.2)
Fabrin answered 26/3 at 16:7 Comment(0)
C
0

I had the issue, it turned out I had to reinstall with sudo on Mac OSX.

pip3 uninstall poetry
sudo pip3 install poetry
Cronin answered 17/4 at 16:20 Comment(0)
P
0

For Mac Users:

If the exporting path to ~/.zshrc won't work for you, Simply try installing poetry with Homebew with the following command:

Brew install poetry

And it will do the job and it will work fine, reason being that poetry is externally-managed-environment for Mac and homebrew does the job for you.

Plat answered 11/7 at 22:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.