# xust-web **Repository Path**: azureroots/xust-web ## Basic Information - **Project Name**: xust-web - **Description**: No description available - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-09-09 - **Last Updated**: 2025-09-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 1、安装uv ### 1.1、在线安装 #### 1.1.1、`Linux/macOS` Use `curl` to download the script and execute it with `sh`: ``` $ curl -LsSf https://astral.sh/uv/install.sh | sh ``` If your system doesn't have `curl`, you can use `wget`: ``` $ wget -qO- https://astral.sh/uv/install.sh | sh ``` Request a specific version by including it in the URL: ``` $ curl -LsSf https://astral.sh/uv/0.7.17/install.sh | sh ``` 安装后重启终端或执行 `source ~/.bashrc` 使 `uv` 生效。 #### 1.1.2、`Windows` Use `irm` to download the script and execute it with `iex`: ```powershell PS> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" ``` Changing the [execution policy](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.4#powershell-execution-policies) allows running a script from the internet. Request a specific version by including it in the URL: ```powershell PS> powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/0.7.17/install. ``` ### 1.2、离线安装 #### 1.2.1、Windows 从 QQ 群文件下载 `uv-x86_64-pc-windows-msvc.zip` 后将其解压到 `X:/bytecreek` 目录下。 随后将 `X:/bytecreek/uv` 路径配置到 环境变量的 `Path` 中即可。 通过`uv --version`命令来查看配置是否成功: ```cmd C:\Users\Administrator>uv --version uv 0.8.15 (8473ecba1 2025-09-03) ``` ### 1.3、安装Python 直接使用 `uv python install 3.13` 去安装时默认从 `github` 下载,所以可能会失败。 这里介绍用离线方式安装。 首先可以从以下地址下载相应的安装包: ```http https://github.com/astral-sh/python-build-standalone/releases/tag/20250902 ``` 我们从 QQ群文件中下载 `uv-python-standalone.7z.auto-unzip.exe` 文件,将其复制到 `X:/bytecreek` 目录中,双击即可解压。 然后在 **Windows资源管理器** 的地址栏中 输入 `%userprofile%` 后 回车即可打开当前用户主目录。 在用户主目录中添加 `uv.toml` 文件,其中内容如下: ```toml # uv.toml index-url = "https://pypi.tuna.tsinghua.edu.cn/simple" extra-index-url = ["https://mirrors.aliyun.com/pypi/simple/","https://repo.huaweicloud.com/repository/pypi/simple"] # 缓存与安装设置 cache-dir = "X:/bytecreek/uv_cache" # 自定义缓存路径 link-mode = "symlink" # 链接模式:symlink/copy/hardlink # 依赖解析策略 resolution = "highest" # 依赖解析策略:lowest/direct/highest # 使用本地文件来充当镜像 python-install-mirror = "file:///X:/bytecreek/uv-python-standalone" ``` 此处请务必注意: - `cache-dir` 必须是你自己机器的磁盘上的路径 - `python-install-mirror` 必须是本地机器上的路径,并且 前缀必须是 `file:///` 以上配置完成后,即可通过以下命令来安装 Python : ``` uv python install 3.13 ``` [Python versions](https://docs.astral.sh/uv/getting-started/features/#python-versions) Installing and managing Python itself. - `uv python install`: Install Python versions. - `uv python list`: View available Python versions. - `uv python find`: Find an installed Python version. - `uv python pin`: Pin the current project to use a specific Python version. - `uv python uninstall`: Uninstall a Python version. ## 2、管理项目 ### 2.1、初始化 通过 `uv init 项目名称` 可以创建并初始化一个 `uv` 项目,比如创建名称为 `hello` 的项目: ```sh X:\bytecreek\codes>uv init hello Initialized project `hello` at `X:\bytecreek\codes\hello` ``` 在执行完 `uv init` 之后会生成以下文件和目录: - `.git` 目录是本地 `Git` 仓库配置所在 - 注意该仓库默认并没有与任何远程仓库关联 - `.gitignore` 用于指定 `Git` 中需要忽略的目录和文件 - `.python-version` 用于设置当前项目正在使用的 Python 版本 - 可以通过配合 `uv python pin 版本号` 来使用 - `main.py` 是默认创建的一个 Python 脚本 - 可以通过 `uv run main.py` 来执行它 (请在激活虚拟环境后再执行) - `pyproject.toml` 是当前项目的配置文件 - 其中的 `requires-python` 决定了当前项目所必须使用的 `Python` 版本 可以通过修改 `requires-python` 的值来设置必须的 `Python` 版本 - `README.md` 项目说明文件 - 其中内容在远程 `Git` 仓库首页可以直接显式 ### 2.2、创建虚拟环境 进入到项目目录后,即可通过 `uv venv` 来**创建**虚拟环境,比如 ```sh X:\bytecreek\codes\hello>uv venv Using CPython 3.13.7 Creating virtual environment at: .venv Activate with: .venv\Scripts\activate ``` 由上可见,新创建的虚拟环境名称为 `.venv` 即 `uv venv` 等同于 `uv venv .venv`。 `uv venv .venv` 末尾的 `.venv` 是默认名称,可以省略为 `uv venv` 来直接创建。 当新创建的虚拟环境名称不是 `.venv` 时,可以显式指定该名称,比如 `uv venv first_venv` 。 ### 2.3、激活虚拟环境 创建好虚拟环境后,还要激活虚拟环境。 只有激活虚拟环境后它才有效,否则新建的虚拟环境将毫无意义。 不同的环境中激活虚拟环境的方式也有所不同,以下是常见的几种激活方式: - **Linux/macOS**: ```sh source .venv/bin/activate ``` - **Windows** 命令提示符: ```cmd .\.venv\Scripts\activate ``` - **Windows PowerShell** ```powershell .venv/Scripts/Activate.ps1 ``` ### 2.4、安装依赖 在确保激活虚拟环境后,即用 `uv add` 命令可为项目安装所需依赖: ```sh (hello) X:\bytecreek\codes\hello>uv add langchain-deepseek Resolved 35 packages in 40ms Installed 34 packages in 335ms + annotated-types==0.7.0 + anyio==4.10.0 + certifi==2025.8.3 + charset-normalizer==3.4.3 + colorama==0.4.6 + distro==1.9.0 + h11==0.16.0 + httpcore==1.0.9 + httpx==0.28.1 + idna==3.10 + jiter==0.10.0 + jsonpatch==1.33 + jsonpointer==3.0.0 + langchain-core==0.3.75 + langchain-deepseek==0.1.4 + langchain-openai==0.3.32 + langsmith==0.4.27 + openai==1.107.0 + orjson==3.11.3 + packaging==25.0 + pydantic==2.11.7 + pydantic-core==2.33.2 + pyyaml==6.0.2 + regex==2025.9.1 + requests==2.32.5 + requests-toolbelt==1.0.0 + sniffio==1.3.1 + tenacity==9.1.2 + tiktoken==0.11.0 + tqdm==4.67.1 + typing-extensions==4.15.0 + typing-inspection==0.4.1 + urllib3==2.5.0 + zstandard==0.24.0 ``` ### 2.5、编写脚本 编辑项目根目录的 `main.py` 文件,使其中内容为: ``` ``` ### 2.6、执行脚本 请确保在 命令提示符 或 PowerShell 中已经激活虚拟环境。 在激活虚拟环境后即可通过 `uv run` 命令来执行 Python 脚本,比如: ```cmd uv run main.py ``` 官方文档中关于 [Projects](https://docs.astral.sh/uv/getting-started/features/#projects) 的内容: Creating and working on Python projects, i.e., with a `pyproject.toml`. - `uv init`: Create a new Python project. - `uv add`: Add a dependency to the project. - `uv remove`: Remove a dependency from the project. - `uv sync`: Sync the project's dependencies with the environment. - `uv lock`: Create a lockfile for the project's dependencies. - `uv run`: Run a command in the project environment. - `uv tree`: View the dependency tree for the project. - `uv build`: Build the project into distribution archives. - `uv publish`: Publish the project to a package index. See the [guide on projects](https://docs.astral.sh/uv/guides/projects/) to get started. ## 3、管理依赖 ### 3.1、查看依赖树 树状列出当前项目下安装的所有依赖,可以通过以下命令实现: ```cmd uv tree ``` 比如: ```cmd X:\bytecreek\codes\hello>uv tree Resolved 38 packages in 1ms hello v0.1.0 ├── dotenv v0.9.9 │ └── python-dotenv v1.1.1 └── langchain-deepseek v0.1.4 ├── langchain-core v0.3.75 │ ├── jsonpatch v1.33 │ │ └── jsonpointer v3.0.0 │ ├── langsmith v0.4.25 │ │ ├── httpx v0.28.1 │ │ │ ├── anyio v4.10.0 │ │ │ │ ├── idna v3.10 │ │ │ │ ├── sniffio v1.3.1 │ │ │ │ └── typing-extensions v4.15.0 │ │ │ ├── certifi v2025.8.3 │ │ │ ├── httpcore v1.0.9 │ │ │ │ ├── certifi v2025.8.3 │ │ │ │ └── h11 v0.16.0 │ │ │ └── idna v3.10 │ │ ├── orjson v3.11.3 │ │ ├── packaging v25.0 │ │ ├── pydantic v2.11.7 │ │ │ ├── annotated-types v0.7.0 │ │ │ ├── pydantic-core v2.33.2 │ │ │ │ └── typing-extensions v4.15.0 │ │ │ ├── typing-extensions v4.15.0 │ │ │ └── typing-inspection v0.4.1 │ │ │ └── typing-extensions v4.15.0 │ │ ├── requests v2.32.5 │ │ │ ├── certifi v2025.8.3 │ │ │ ├── charset-normalizer v3.4.3 │ │ │ ├── idna v3.10 │ │ │ └── urllib3 v2.5.0 │ │ ├── requests-toolbelt v1.0.0 │ │ │ └── requests v2.32.5 (*) │ │ └── zstandard v0.24.0 │ ├── packaging v25.0 │ ├── pydantic v2.11.7 (*) │ ├── pyyaml v6.0.2 │ ├── tenacity v9.1.2 │ └── typing-extensions v4.15.0 └── langchain-openai v0.3.32 ├── langchain-core v0.3.75 (*) ├── openai v1.106.1 │ ├── anyio v4.10.0 (*) │ ├── distro v1.9.0 │ ├── httpx v0.28.1 (*) │ ├── jiter v0.10.0 │ ├── pydantic v2.11.7 (*) │ ├── sniffio v1.3.1 │ ├── tqdm v4.67.1 │ │ └── colorama v0.4.6 │ └── typing-extensions v4.15.0 └── tiktoken v0.11.0 ├── regex v2025.9.1 └── requests v2.32.5 (*) (*) Package tree already displayed ``` 另外,仅列出当前项目中已经安装的依赖列表,还可以通过以下命令实现: ```cmd uv pip list ``` 比如: ```cmd X:\bytecreek\codes\hello>uv pip list Package Version ------------------ -------- annotated-types 0.7.0 anyio 4.10.0 certifi 2025.8.3 charset-normalizer 3.4.3 colorama 0.4.6 distro 1.9.0 dotenv 0.9.9 h11 0.16.0 httpcore 1.0.9 httpx 0.28.1 idna 3.10 jiter 0.10.0 jsonpatch 1.33 jsonpointer 3.0.0 langchain-core 0.3.75 langchain-deepseek 0.1.4 langchain-openai 0.3.32 langsmith 0.4.25 openai 1.106.1 orjson 3.11.3 packaging 25.0 pydantic 2.11.7 pydantic-core 2.33.2 python-dotenv 1.1.1 pyyaml 6.0.2 regex 2025.9.1 requests 2.32.5 requests-toolbelt 1.0.0 sniffio 1.3.1 tenacity 9.1.2 tiktoken 0.11.0 tqdm 4.67.1 typing-extensions 4.15.0 typing-inspection 0.4.1 urllib3 2.5.0 zstandard 0.24.0 ``` 以上仅列出依赖名称及版本号,没有列出它们之间的关系。 ### 3.2、安装依赖 为当前项目安装依赖,可以通过以下命令实现: ```cmd uv add 依赖名称[==版本号] ``` 其中 `[==版本号]` 是可选的。 比如,直接安装 `langchain-deepseek` 而不显式设置版本可以使用: ```cmd uv add langchain-deepseek ``` 安装 `dotenv` 并显式指定版本可以通过以下形式实现: ```cmd uv add dotenv==0.9.9 ``` ### 3.3、移除依赖 若某个依赖不再被使用,或者版本安装错误,则可以将该依赖从工程中移除: ```cmd uv remove 依赖名称[==版本号] ``` 其中 `[==版本号]` 是可选的。 比如,卸载 `dotenv` 依赖: ```cmd X:\bytecreek\codes\hello>uv remove dotenv Resolved 36 packages in 1.50s Uninstalled 2 packages in 9ms - dotenv==0.9.9 - python-dotenv==1.1.1 ``` ### 3.4、同步依赖 一个项目所需要的依赖被通过 `pyproject.toml` 和 `uv.lock` 记录在项目中。 当从远程仓库将项目克隆到本地后,本地项目中是没有虚拟环境也没有相关依赖的。 因此我们应该首先在本地项目中**创建**虚拟环境: ```cmd uv venv ``` 随后将该虚拟环境**激活**,比如在 Windows系统的 命令提示符中可以使用以下形式激活: ``` .\.venv\Scripts\activate ``` 最后我们可以通过 `uv sync` 来**"安装"**依赖: ``` uv sync ``` 此时的 `uv` 会根据 `pyproject.toml` 中的配置和`uv.lock`中的记录来为当前虚拟环境安装依赖。 等所有依赖安装完毕,即可拥有与远程仓库作者一样的环境。 > 官方文档中对 `uv sync` 的说法是 “ Sync the project's dependencies with the environment ” ,翻译过来就是 “将项目的依赖项与环境同步”,实际上若依赖尚未安装,`uv` 会首先安装这些依赖。