docs
Poetry

Poetry (opens in a new tab)

安装

Mac、Linux 安装

  1. 推荐:curl -sSL https://install.python-poetry.org | python3 -

    • root 配置所有用户可用:export POETRY_HOME=/usr/local
  2. 通过 pip:pip install poetry

Windows 安装

注意事项, windows 安装后,让添加的 path 路径是不正确的。 需要日志里面,根据获取真实的路径

Actual environment location may have moved due to redirects, links or junctions.
  Requested location: "C:\Users\muyu\AppData\Roaming\pypoetry\venv\Scripts\python.exe"
  Actual location:    "C:\Users\muyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\Roaming\pypoetry\venv\Scripts\python.exe"

所以真实的路径为:C:\Users\muyu\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\Roaming\pypoetry\venv\Scripts

技巧

  1. 安装包:
    • 包名 poetry add httpx
    • url: poetry add https://xxxx.com/xxx.whl
    • 本地目录:poetry add -e ../xxx
    • 安装指定源:poetry add ship --source pypiserver
  2. 执行命令:poetry run xxx
  3. 进入虚拟环境:poetry shell

项目配置

  1. 初始化项目:poetry init

poetry 配置

  1. 查看配置:poetry config --list

发布包

  1. 添加发布源:poetry config --local repositories.pypiserver http://100.64.0.9:8080
  2. 打包:poetry build
  3. 发布:poetry publish -r pypiserver --username admin --password admin