0
0
mirror of https://gitea.com/gitea/docs.git synced 2025-05-11 09:55:06 +00:00
Files
appleboy dbfa0ba454 docs: add zh-tw folder (#195)
Signed-off-by: appleboy <appleboy.tw@gmail.com>
Reviewed-on: https://gitea.com/gitea/docs/pulls/195
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: appleboy <appleboy.tw@gmail.com>
Co-committed-by: appleboy <appleboy.tw@gmail.com>
2025-04-04 23:28:16 +00:00

76 lines
2.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
date: "2021-07-20T00:00:00+00:00"
slug: "pypi"
sidebar_position: 100
---
# PyPI 套件註冊表
為您的用戶或組織發布 [PyPI](https://pypi.org/) 套件。
## 需求
要使用 PyPI 套件註冊表,您需要使用工具 [pip](https://pypi.org/project/pip/) 來消費和 [twine](https://pypi.org/project/twine/) 來發布套件。
## 配置套件註冊表
要註冊套件註冊表,您需要編輯本地 `~/.pypirc` 文件。添加
```ini
[distutils]
index-servers = gitea
[gitea]
repository = https://gitea.example.com/api/packages/{owner}/pypi
username = {username}
password = {password}
```
| 佔位符 | 描述 |
| ---------- | ------------------------------------------------------------------------------------------------------------------- |
| `owner` | 套件的擁有者。 |
| `username` | 您的 Gitea 用戶名。 |
| `password` | 您的 Gitea 密碼。如果您使用 2FA 或 OAuth請使用 [個人訪問令牌](development/api-usage.md#authentication) 代替密碼。 |
## 發布套件
運行以下命令來發布套件:
```shell
python3 -m twine upload --repository gitea /path/to/files/*
```
套件文件的擴展名為 `.tar.gz``.whl`
如果已經存在同名同版本的套件,您不能發布該套件。您必須先刪除現有的套件。
## 安裝套件
要從套件註冊表中安裝 PyPI 套件,請執行以下命令:
```shell
pip install --index-url https://{username}:{password}@gitea.example.com/api/packages/{owner}/pypi/simple --no-deps {package_name}
```
| 參數 | 描述 |
| -------------- | ------------------------------- |
| `username` | 您的 Gitea 用戶名。 |
| `password` | 您的 Gitea 密碼或個人訪問令牌。 |
| `owner` | 套件的擁有者。 |
| `package_name` | 套件名稱。 |
例如:
```shell
pip install --index-url https://testuser:password123@gitea.example.com/api/packages/testuser/pypi/simple --no-deps test_package
```
您可以使用 `--extra-index-url` 代替 `--index-url`,但這會使您容易受到依賴混淆攻擊,因為 `pip` 在檢查指定的自定義存儲庫之前會先檢查官方 PyPi 存儲庫。請閱讀 `pip` 文檔以獲取更多信息。
## 支持的命令
```
pip install
twine upload
```