# py_test **Repository Path**: zhuto666/py_test ## Basic Information - **Project Name**: py_test - **Description**: py语言与mysql数据库连接实现,开发增删改查功能。 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-22 - **Last Updated**: 2025-05-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Python项目安装依赖及运行命令 [TOC] ## 安装Python3 ### ① Windows中安装Python3 > https://www.python.org/ftp/python/3.12.0/python-3.12.0-amd64.exe ## 安装Python包管理器uv ### ① 直接通过 curl 安装(推荐) > 安装 uv(适用于 Linux/macOS) curl -LsSf https://astral.sh/uv/install.sh | sh > 安装完成后,按提示将 uv 加入 PATH(或重启终端): > source ~/.bashrc # 或 source ~/.zshrc ### ② 通过 pip 安装 > pip install uv ### 验证安装 > uv --version ## 使用uv创建项目虚拟环境,激活项目虚拟环境 > uv 的虚拟环境管理比 venv/virtualenv 更快,且兼容 pip 和 requirements.txt。 ### ① 创建虚拟环境 > uv venv .venv # 在当前目录创建 .venv 虚拟环境 > > 等效于 python -m venv .venv,但速度更快。 ### ② 激活虚拟环境 >Linux/macOS: >source .venv/bin/activate > Windows(PowerShell): > .\.venv\Scripts\activate ## 使用 uv 安装依赖 (推荐) > uv sync (安装 pyproject.toml 文件下的所有包) > uv pip install fastapi uvicorn (安装指定包) ### ① 使用 poetry 安装 ```powershell poetry install ``` ### ② 直接安装包(类似 pip install) ```powershell uv pip install fastapi uvicorn ``` ### ③ 从 requirements.txt 安装 ``` powershell uv pip install -r requirements.txt ``` ## 启动服务 > 正常运行 ```powershell uvicorn main:app --port=5000 --host=0.0.0.0 ``` > 后台运行 ```powershell nohup uvicorn main:app --port=5000 --host=0.0.0.0 > output.log 2>&1 & ``` ## 跳出虚拟环境的命令 ```powershell deactivate ```