📝 字数:working on
Poetry¶
Estimated time to read: 2 minutes
tool.poetry vs project¶
project defined by [PEP621](https://peps.python.org/pep-0621/), tool.
Add from wle need to relative or absolute path¶
portry add file.whl # wrong
poetry add ./file.whl # right
How to Migrate from venv to poetry¶
pipx¶
推荐使用pipx安装poetry,但是pipx必须绑定某个python使用,因此绑定全局的python,同时将poetry通过全局的python下的 全局pipx安装,也就是得到全局的poetry。
修改源¶
全局¶
poetry config repositories.pypi https://pypi.tuna.tsinghua.edu.cn/simple
poetry config --list
poetry config unset repositories.pypi # 恢复
仅修改当前项目¶
[[tool.poetry.source]]
name = "tsinghua"
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
priority = "primary"
[[tool.poetry.source]]
name = "pypi"
url = "https://pypi.org/simple"
priority = "supplemental"
How¶
从requirements.txt安装¶
poetry 本身不支持,只能逐个安装;
cat requirements.txt | xargs poetry add
如何在新的路径下使用旧的环境¶
poetry init # 创建新环境
poetry config virtualenvs.path # 找到并进入环境所在路径
# delete 新环境
# rename 旧环境 为新环境名称
根据pyproject.yaml修改poetry.lock¶
poetry lock
poetry show module依据poetry.lock¶
$VIRTUAL_ENV环境变量可能影响使用的环境¶
unset VIRTUAL_ENV清除,这个貌似是每个poetry项目单独的