安装 poetry 环境

Poetry is a tool for dependency management and packaging in Python. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. Poetry offers a lockfile to ensure repeatable installs, and can build your project for distribution.

划重点:依赖管理 包管理

 

安装很简单,就一行!

( 先确保安好Python3.7+

然后:

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

 

根据提示(Add `export PATH="/root/.local/bin:$PATH"` to your shell configuration file.)把bin目录加入环境变量!

poetry --version    #验证是否安装完成

 

换源 

在项目的配置 pyproject.toml 最后面添加要用的源

[[tool.poetry.source]]
name = "tsinghua"
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
default = true

 

基本使用:

poetry new poetry-demo    # 创建脚手架 (项目模板)

poetry init    # 在当前目录创建一个 pyproject.toml 

 

环境管理:

poetry env list             #查看环境

poetry run python xxxx.py       #直接在当前项目环境中运行

poetry shell             #进入当前项目环境 (貌似可以替代 conda 了 哈哈哈

 

配置相关:

poetry confiig --list        # 查看当前配置

 

依赖管理:

poetry add gym          #安装最新稳定版本的gym
poetry add gym --dev       #指定为开发依赖(写到pyproject.toml中的[tool.poetry.dev-dependencies]下)
poetry add gym=0.26.2       #指定具体的版本
poetry install           #安装pyproject.toml文件中的全部依赖
poetry install --no-dev       #只安装[tool.poetry.dependencies]下的(一般部署时使用)

 

清理缓存:(删除下列文件夹)

~/.cache/pypoetry/cache/
~/.cache/pypoetry/artifacts/

 

ENJOY~

 

posted @ 2022-11-04 11:17  LightingCui  阅读(2501)  评论(0编辑  收藏  举报