由于使用了develop = true包,Poetry 有一些陈旧的依赖关系。Poetry 无法自行判断依赖项已更新。如何强制 Poetry 重新安装其 virtualenv 中的所有内容来解决此问题?
Mik*_*maa 68
这些说明仅适用于适用于 Linux 的 Windows 子系统的 Linux/macOS。对于 Microsoft Windows shell,请使用您自己的命令行知识来应用这些说明。
要在当前工作目录(UNIX shell)中重新安装 Poetry 环境的软件包:
# Enter the current Poetry environment
poetry shell
# Remove the current environment
# as referred by path to Python interpreter
poetry env remove $(which python)
# Reinstall from Poetry's cache
poetry install
Run Code Online (Sandbox Code Playgroud)
在文件夹中执行以下操作pyproject.toml:
# Stop the current virtualenv if active or alternative use
# `exit` to exit from a Poetry shell session
deactivate
# Remove all the files of the current environment of the folder we are in
POETRY_LOCATION=`poetry env info -p`
echo "Poetry is $POETRY_LOCATION"
rm -rf "$POETRY_LOCATION"
# Reactivate Poetry shell
poetry shell
# Install everything
poetry install
Run Code Online (Sandbox Code Playgroud)
Poetry 可能引用您安装的 Python 版本,因此您可能会告诉它也更改其到您的解释器的链接python:
# Make Poetry to use python 3.9 from Homebrew, installed earlier
poetry env use `which python3.9`
poetry shell
python -V
Run Code Online (Sandbox Code Playgroud)
Python 3.9.9
Run Code Online (Sandbox Code Playgroud)
如果poetry命令本身损坏并且不再运行,您可以通过以下方式重新安装 Poetry:
which poetry
Run Code Online (Sandbox Code Playgroud)
/Users/mikkoohtamaa/.poetry/bin/poetry
Run Code Online (Sandbox Code Playgroud)
然后删除它并安装:
# macOS
rm -rf /Users/mikkoohtamaa/.poetry
rm -rf "/Users/$USER/Library/Application Support/pypoetry/venv"
# Linux
rm -rf ~/.local/share/pypoetry/
# Download and run Poetry install script
# If your curl is messed up you can try with --insecure flag
curl -sSL https://install.python-poetry.org/ | python3 - --force
Run Code Online (Sandbox Code Playgroud)
有时,在您升级 Python(例如使用 Homebrew)后,Poetry 可能无法安装。这可能与由 Poetry 决定使用哪个 Python 版本这一事实有关。
您看到的错误可能包括:
# Stop the current virtualenv if active or alternative use
# `exit` to exit from a Poetry shell session
deactivate
# Remove all the files of the current environment of the folder we are in
POETRY_LOCATION=`poetry env info -p`
echo "Poetry is $POETRY_LOCATION"
rm -rf "$POETRY_LOCATION"
# Reactivate Poetry shell
poetry shell
# Install everything
poetry install
Run Code Online (Sandbox Code Playgroud)
dyld[6526]: Library not loaded: @loader_path/../Python
Referenced from: <7295E559-55D4-3ACA-9820-D95D1F4AE151> /Users/moo/Library/Application Support/pypoetry/venv/bin/python3.10
Reason: tried: '/Users/moo/Library/Application Support/pypoetry/venv/bin/../Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS@loader_path/../Python' (no such file), '/Users/moo/Library/Application Support/pypoetry/venv/bin/../Python' (no such file), '/usr/local/lib/Python' (no such file), '/usr/lib/Python' (no such file, not in dyld cache)
Traceback:
File "<stdin>", line 923, in main
File "<stdin>", line 562, in run
Run Code Online (Sandbox Code Playgroud)
在这种情况下,推荐的方法是放弃基于 Homebrew 的 Python 并开始使用pyenv:
# Make Poetry to use python 3.9 from Homebrew, installed earlier
poetry env use `which python3.9`
poetry shell
python -V
Run Code Online (Sandbox Code Playgroud)
然后在新的 shell 中安装特定的 Python 版本并检查它是否正在使用:
Python 3.9.9
Run Code Online (Sandbox Code Playgroud)
指向 pyenv:
/Users/moo/.pyenv/shims/python
Run Code Online (Sandbox Code Playgroud)
现在使用特定的 Python 版本重新安装 Poetry,它应该可以工作:
which poetry
Run Code Online (Sandbox Code Playgroud)
Dam*_*ien 19
官方文档推荐使用该poetry env remove命令,该命令接受以下任意语法:
poetry env remove /full/path/to/python
poetry env remove python3.11
poetry env remove 3.11
poetry env remove test-O3eWbxRl-py3.11
Run Code Online (Sandbox Code Playgroud)
您可以使用以下命令一次性删除所有虚拟环境poetry env remove --all
与接受的答案一样,这需要分别重新poetry shell创建poetry install环境并重新安装依赖项。
| 归档时间: |
|
| 查看次数: |
56443 次 |
| 最近记录: |