PDM 介绍
mac 上直接使用 brew install pdm
安装,其它系统官方提供了一个一键安装的shell脚本。安装完成后,创建一个项目目录 test-pdm ,在目录中使用 pdm init
命令初始化项目:
➜ test-pdm pdm init
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
0. /usr/local/opt/python@3.9/bin/python3.9 (3.9)
1. /Library/Developer/CommandLineTools/usr/bin/python3 (3.8)
2. /Library/Frameworks/Python.framework/Versions/Current/bin/python3.8 (3.8)
3. /usr/local/bin/pypy3.7 (3.7)
4. /usr/local/bin/pypy (2.7)
5. /usr/local/Cellar/pdm/2.1.2/libexec/bin/python3.10 (3.10)
Please select (0): 2
Using Python interpreter: /Library/Frameworks/Python.framework/Versions/Current/bin/python3.8 (3.8)
Would you like to create a virtualenv with /Library/Frameworks/Python.framework/Versions/Current/bin/python3.8? [y/n] (y): y
Virtualenv is created successfully at /Users/yoo/tmp/test-pdm/.venv
Is the project a library that will be uploaded to PyPI [y/n] (n): n
License(SPDX name) (MIT):
Author name (game404):
Author email (studyoo@foxmail.com):
Python requires('*' to allow any) (>=3.8):
Changes are written to pyproject.toml.
pdm
比较方便的地方是会扫描出系统的python解释器,提示用户选择解释器版本, 比如上面日志显示有5个python版本,有点乱:( 。初始化完成后,生成项目描述文件pyproject.toml
内容如下:
[project]
name = ""
version = ""
description = ""
authors = [
{name = "game404", email = "studyoo@foxmail.com"},
]
dependencies = []
requires-python = ">=3.8"
license = {text = "MIT"}
[build-system]
requires = ["pdm-pep517>=1.0.0"]
build-backend = "pdm.pep517.api"
复制代码
当然在项目目录下,也会创建一个隐藏的 .venv 目录,用来存放解释器,和其它工具一致。
安装包之前先使用 pdm config pypi.url https://pypi.tuna.tsinghua.edu