已安装 Poetry 但“poetry:未找到命令”

Str*_*420 64 python windows python-poetry

最近我在诗歌方面遇到了一百万零一个问题。

我昨天已经完全安装并工作了,但是重新启动我的机器后,我又遇到了问题;(

即使在重新启动后,是否有办法在我的终端中始终识别诗歌?


系统规格:

  • Windows 10,
  • Visual Studio 代码,
  • Bash - WSL Ubuntu CLI,
  • Python 3.8。

终端:

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$ 
Run Code Online (Sandbox Code Playgroud)

如果我可以在帖子中添加其他内容以帮助进一步澄清,请告诉我。

Pat*_*Yan 101

因为这是“未找到诗歌命令”的 StackOverflow 结果...

对于 Mac 用户,请.zshrc在您的主文件夹中创建一个包含以下内容的文件:

export PATH="$HOME/.local/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

  • 你救了我的命。由于某种原因,即使通过推荐的方法安装诗歌后,我根本没有 ~/.poetry/bin 目录。事实证明可执行文件位于 ~/.local/bin 中 (6认同)

Str*_*420 43

当我运行此命令时,在 bash 终端关闭后:

export PATH="$HOME/.poetry/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)

poetry然后命令被识别。

然而,仅此还不够。因为每次关闭终端时我都需要运行export.

可能需要保存在文件中。

  • 根据[文档](https://python-poetry.org/docs/),这个答案应该在 Unix 上使用 `export PATH="$HOME/.local/bin:$PATH"` 进行更新。最好将其写在 `.bashrc` 或 `.zshrc` 中。 (9认同)

Rex*_*ker 25

我将诗歌更新到 v1.2.2(2022 年 11 月),但在正确设置路径时遇到问题。这是我找到的路径定义:

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

使用以下命令将其临时添加到您的路径中:
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\pypoetry\venv\Scripts

或者在您常用的 Windows 环境设置中进行设置


小智 13

在Windows 11中,经过长时间痛苦的powershell实验并阅读诗歌安装文档,我解决了这样的问题:

  1. 使用以下命令安装诗歌:
    (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

当系统报告诗歌已成功安装时,对于诗歌,您需要注册其安装文件夹的路径。输入poetry --version命令时,powershell 中出现错误,诗歌未知,我无法通过命令行注册路径。

  1. 通过Windows文件夹窗口设置,我使隐藏的文件夹和文件可见,并转到诗歌的安装位置:C:\Users\user\AppData\Roaming\Python\Scripts.

  2. 为了让python能够看到poetry的路径,我从C:\Users\user\AppData\Roaming\Python\Scriptspython工作环境中的位置复制了poetry.exe:C:\Users\user\AppData\Local\Programs\Python\Python310\Scripts这样。

Pip 也位于 Local。问题解决了,powershell中的命令poetry --version显示了诗歌版本。我希望这能帮到您!

  • 正如目前所写的,您的答案尚不清楚。请[编辑]添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。您可以[在帮助中心](/help/how-to-answer)找到有关如何写出好的答案的更多信息。 (3认同)

小智 12

为了跟进 @StressedBoi69420 的答案,您能否将他建议的行添加 export PATH="$HOME/.poetry/bin:$PATH" 到您的.bashrc?

根据另一篇 Stack Overflow 帖子What is the default install path for Poetry和 @arshbot 的答案,我已将这一行添加 export PATH=$PATH:$HOME/.poetry/bin到我的中.zshrc,它似乎正在工作。


小智 10

安装后 - 要将诗歌添加到 Mac 中的 shell 脚本中,请在终端中添加以下命令

\n

open ~/.zshrc

\n

如果之前未创建 zshrc 文件,则使用以下命令创建它 -

\n

\xc2\xa0 .zshrc\xc2\xa0 文件在 macOS Catalina 中默认不存在,我们需要创建它。

\n

创建步骤:

\n
    \n
  1. 打开终端
  2. \n
  3. 键入\xc2\xa0 touch ~/.zshrc\xc2\xa0 以创建相应的文件。(touch\xc2\xa0 命令将在当前目录中创建 \xc2\xa0 .zshrc\xc2\xa0 但它将被隐藏)
  4. \n
  5. 按回车键
  6. \n
\n

打开 zshrc 文件

\n
    \n
  1. 打开终端 > 并输入:\xc2\xa0open ~/.zshrc

    \n

    在 .zshrc 文件中添加行 -

    \n
  2. \n
\n

export PATH="$HOME/.local/bin:{$PATH}\xe2\x80\x9d

\n

将上述命令添加到 .zshrc 文件后,返回终端并通过 - 刷新终端

\n
source ~/.zshrc\n
Run Code Online (Sandbox Code Playgroud)\n

然后在终端执行以下命令

\n
poetry --version\n
Run Code Online (Sandbox Code Playgroud)\n

如果您获得版本名称,那么您就可以使用了!

\n

此外,在其他操作系统环境中安装时,您可以参考https://python-poetry.org/docs/#installation了解更多信息。

\n


mea*_*ars 10

对于 Windows(在 powershell 上)请尝试以下操作:

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

(来自页面 https://www.jetbrains.com/help/pycharm/poetry.html#c2dbb15c

  • 如果您的路径已经很长(超过 1024 个字符),请在运行此命令时非常小心,因为它会截断并仅保留路径中的前 1024 个字符,并且可能会导致您的电脑损坏 (2认同)