Skip to content

Commit aecf783

Browse files
committed
docs(tools): add pyenv/poetry/* & pyenv/launcher
1 parent a674c72 commit aecf783

File tree

5 files changed

+603
-340
lines changed

5 files changed

+603
-340
lines changed

docs/tools/pyenv/launcher.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Python Launcher
2+
3+
[[TOC]]
4+
5+
## 1. Python Launcher 使用
6+
7+
此功能适用于 Windows。
8+
9+
在 Windows 上安装 Python 时,默认会安装 Python Launcher,用于管理和执行不同的 Python 版本。
10+
11+
安装后可以使用 `py` 命令查看和管理计算机中不同的 Python。`py` 命令默认可以代替 `python` 命令使用。
12+
13+
直接启动 Python:
14+
15+
```bash
16+
py
17+
```
18+
19+
查看已安装的 Python:
20+
21+
```bash
22+
py -0
23+
```
24+
25+
查看帮助:
26+
27+
```bash
28+
py --help
29+
```
30+
31+
除了 Python 程序默认的命令行参数外,`py` 还包括下面的参数:
32+
33+
| 参数 | 说明 |
34+
| --------------------- | ------------------------------------------------- |
35+
| `-2` | 启动最新的 Python 2.x 版本 |
36+
| `-3` | 启动最新的 Python 3.x 版本 |
37+
| `-X.Y` | 启动指定的 Python 版本如果存在匹配的 64 位 Python |
38+
| `-X.Y-32` | 启动指定的 32 位 Python 版本 |
39+
| `-X-32` | 启动最新的 32 位 Python 版本 X |
40+
| `-X.Y-64` | 启动指定的 64 位 Python 版本 |
41+
| `-X-64` | 启动最新的 64 位 Python 版本 X |
42+
| `-0``--list` | 列出可用的 Python |
43+
| `-0p``--list-paths` | 列出路径 |
44+
45+
## 2. 配置
46+
47+
默认 `py.exe` 被安装在 `C:\Windows\py.exe` 路径下。
48+
49+
如果需要修改默认启动的 Python 版本,可以创建 `C:\Windows\py.ini` 文件,内容如下:
50+
51+
```ini
52+
[defaults]
53+
python=3.10
54+
```
55+
56+
这样,`py` 命令就会默认启动 Python 3.10。

docs/tools/pyenv/poetry/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Poetry
2+
3+
<AutoCatalog />

docs/tools/pyenv/poetry/poetry.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Poetry
2+
3+
[[TOC]]
4+
5+
## 1. Poetry 简介
6+
7+
Poetry 是一款用于 Python 依赖性管理和打包的工具。它允许你声明项目依赖的库,并为你管理(安装/更新)它们。Poetry 提供一个锁文件,以确保可重复安装,并可构建项目以供发布。
8+
9+
Poetry 需要 Python 3.8 以上版本。它是多平台的,目标是让它在 Linux、MacOS 和 Windows 上同样运行良好。
10+
11+
推荐使用 `pipx` 安装:
12+
13+
```bash
14+
pipx install poetry
15+
```
16+
17+
如果你没有安装 `pipx`,可以使用 `pip` 安装 `pipx`
18+
19+
```bash
20+
pip install pipx
21+
```
22+
23+
对于 Linux 或 MacOS 系统,可以使用官方命令安装:
24+
25+
```bash
26+
curl -sSL https://install.python-poetry.org | python -
27+
```
28+
29+
对于 Windows 则可以使用 PowerShell 安装:
30+
31+
```powershell
32+
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
33+
```
34+
35+
这种方法需要手动添加路径:
36+
37+
- MacOS:`~/Library/Application Support/pypoetry`
38+
- Linux/Unix:`~/.local/share/pypoetry`
39+
- Windows:`%APPDATA%\pypoetry`
40+
41+
## 2. Poetry 基本使用
42+
43+
查看命令的使用方式:
44+
45+
```bash
46+
poetry list
47+
```
48+
49+
创建项目:
50+
51+
```bash
52+
poetry new poetry-demo
53+
```
54+
55+
这将生成如下目录:
56+
57+
```console
58+
poetry-demo
59+
├── pyproject.toml
60+
├── README.md
61+
├── poetry_demo
62+
│ └── __init__.py
63+
└── tests
64+
└── __init__.py
65+
```
66+
67+
初始化项目:
68+
69+
```bash
70+
cd pre-existing-project
71+
poetry init
72+
```
73+
74+
这总是可以配合虚拟环境使用。
75+
76+
Poetry 还可以配合 [`pre-commit`](https://pre-commit.com/) 使用,可以在项目中添加 `.pre-commit-config.yaml` 文件,然后运行 `pre-commit install` 安装钩子。
77+
78+
```yml
79+
repos:
80+
- repo: https://github.com/python-poetry/poetry
81+
rev: '' # add version here
82+
hooks:
83+
- id: poetry-check
84+
args: ["-C", "./subdirectory"]
85+
- id: poetry-lock
86+
args: ["-C", "./subdirectory"]
87+
- id: poetry-export
88+
args: ["-C", "./subdirectory", "-f", "requirements.txt", "-o", "./subdirectory/requirements.txt"]
89+
- id: poetry-install
90+
args: ["-C", "./subdirectory"]
91+
```

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@
2121
"update-package": "pnpm dlx vp-update"
2222
},
2323
"devDependencies": {
24-
"@vuepress/client": "2.0.0-beta.68",
25-
"@vuepress/plugin-shiki": "2.0.0-beta.68",
26-
"@vuepress/utils": "2.0.0-beta.68",
24+
"@vuepress/client": "2.0.0-rc.0",
25+
"@vuepress/plugin-shiki": "2.0.0-rc.0",
26+
"@vuepress/utils": "2.0.0-rc.0",
2727
"github-slugger": "^2.0.0",
2828
"katex": "^0.16.9",
2929
"mermaid": "^10.6.1",
3030
"vue": "^3.3.8",
31-
"vuepress": "2.0.0-beta.68",
32-
"vuepress-plugin-auto-catalog": "2.0.0-beta.250",
33-
"vuepress-plugin-copy-code2": "2.0.0-beta.250",
34-
"vuepress-plugin-md-enhance": "2.0.0-beta.250",
35-
"vuepress-plugin-search-pro": "2.0.0-beta.250"
31+
"vuepress": "2.0.0-rc.0",
32+
"vuepress-plugin-auto-catalog": "2.0.0-rc.0",
33+
"vuepress-plugin-copy-code2": "2.0.0-rc.0",
34+
"vuepress-plugin-md-enhance": "2.0.0-rc.0",
35+
"vuepress-plugin-search-pro": "2.0.0-rc.0"
3636
}
3737
}

0 commit comments

Comments
 (0)