> ## Documentation Index
> Fetch the complete documentation index at: https://openfic.syrizelink.top/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 使用 Python

<Note>
  在开始之前，请确保你的系统上已经安装了 [Python](https://www.python.org/downloads/)
</Note>

<Warning>
  OpenFic 仅支持 **Python 3.12 和 3.13**，如果使用其它版本可能会在安装或运行时出错
</Warning>

## 快速开始

### pip

<Note>
  直接使用 pip 进行安装可能会对系统的全局 Python 环境造成污染，如果你不希望影响现有环境，请考虑使用 uv、Conda或Venv
</Note>

<Steps>
  <Step title="安装 OpenFic">
    ```bash theme={null}
    pip install openfic
    ```
  </Step>

  <Step title="启动服务器">
    ```shellscript theme={null}
    openfic serve
    ```
  </Step>

  <Step title="打开 OpenFic">
    等待启动完成后，在浏览器中打开 [http://localhost:8000](http://localhost:8000)。
  </Step>
</Steps>

### uv

<Steps>
  <Step title="安装 uv">
    前往 [Getting Started](https://docs.astral.sh/uv/getting-started/) 按照指引安装 uv。
  </Step>

  <Step title="运行 OpenFic">
    ```bash theme={null}
    uvx --python 3.12 openfic@latest serve
    ```
  </Step>

  <Step title="打开 OpenFic">
    等待启动完成后，在浏览器中打开 [http://localhost:8000](http://localhost:8000)。
  </Step>
</Steps>

### Conda

<Steps>
  <Step title="安装 Anaconda 或 Miniconda">
    前往 [Getting Started](https://www.anaconda.com/docs/getting-started/installation) 按照指引安装 Anaconda 或 Miniconda。
  </Step>

  <Step title="创建 Conda 虚拟环境">
    ```shellscript theme={null}
    conda create -n openfic python=3.12
    ```
  </Step>

  <Step title="激活环境">
    ```shellscript theme={null}
    conda activate openfic
    ```
  </Step>

  <Step title="安装 OpenFic">
    ```shellscript theme={null}
    pip install openfic
    ```
  </Step>

  <Step title="启动服务器">
    ```bash theme={null}
    openfic serve
    ```
  </Step>

  <Step title="打开 OpenFic">
    等待启动完成后，在浏览器中打开 [http://localhost:8000](http://localhost:8000)。
  </Step>
</Steps>

### Venv

`venv` 是 Python 内置的虚拟环境工具

<Steps>
  <Step title="创建虚拟环境">
    ```shellscript theme={null}
    python -m venv .venv
    ```

    该命令会在当前目录下创建，因此在运行前请先切换至期望的安装路径
  </Step>

  <Step title="激活虚拟环境">
    Linux/macOS：

    ```shellscript theme={null}
    source venv/bin/activate
    ```

    Windows：

    ```shellscript theme={null}
    venv\Scripts\activate
    ```
  </Step>

  <Step title="安装 OpenFic">
    ```shellscript theme={null}
    pip install openfic
    ```
  </Step>

  <Step title="启动服务器">
    ```bash theme={null}
    openfic serve
    ```
  </Step>

  <Step title="打开 OpenFic">
    等待启动完成后，在浏览器中打开 [http://localhost:8000](http://localhost:8000)。
  </Step>
</Steps>

## 常用配置

### 自定义端口

如果主机的 `8000` 端口已经被占用，可以使用 `--port` 指定其他端口：

```bash theme={null}
openfic serve --port 8080
```

然后打开 [http://localhost:8080](http://localhost:8080)。

### 指定数据目录

OpenFic 默认会将数据写入 `~/.openfic`，你可以通过环境变量 `OPENFIC_DATA_DIR` 指定其他目录：

Linux/macOS：

```bash theme={null}
OPENFIC_DATA_DIR="$HOME/OpenFic/data" openfic serve
```

Windows：

```powershell theme={null}
$env:OPENFIC_DATA_DIR = "$HOME\OpenFic\data"
openfic serve
```

如果使用 `uvx`，请在启动命令前设置：

```bash theme={null}
OPENFIC_DATA_DIR="$HOME/OpenFic/data" uvx --python 3.12 openfic@latest serve
```

## 更新

### pip、Conda 和 Venv

激活对应的虚拟环境后执行：

```bash theme={null}
pip install --upgrade openfic
```

### uv

使用 `@latest` 运行时，重新执行启动命令即可获取最新版本：

```bash theme={null}
uvx --python 3.12 openfic@latest serve
```

## 卸载

### pip 或 Venv

在对应环境中执行：

```bash theme={null}
python -m pip uninstall openfic
```

如果不再需要虚拟环境，可以删除项目目录中的 `.venv` 文件夹。

### Conda

```bash theme={null}
conda env remove -n openfic
```

### uv

uvx 不会将 OpenFic 安装到当前 Python 环境，因此不需要单独卸载，需要时可以按照 [uv 缓存文档](https://docs.astral.sh/uv/concepts/cache/) 进行清理。

<Warning>
  卸载软件包或删除虚拟环境不会删除 `~/.openfic` 中的项目和配置。如果确认不再需要这些数据，请手动删除数据目录。
</Warning>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.