Label Studio 从源码安装怎么配置 Python 环境、迁移数据库并启动服务?
【免费下载链接】label-studioLabel Studio is a multi-type data labeling and annotation tool with standardized output format项目地址: https://gitcode.com/GitHub_Trending/la/label-studio
如果你需要跑 Label Studio 的 nightly 构建、做二次开发或贡献代码,就需要从源码把服务在本地跑起来,而不是安装 PyPI 上的发布包。整个流程是四步:准备干净的 Python 环境并装好依赖、运行数据库迁移(默认 SQLite,可选 PostgreSQL)、收集静态文件、以开发模式启动服务,最后在浏览器打开http://localhost:8080确认服务可用。操作步骤来自 docs/source/guide/install.md 的 “Install from source” 一节,数据库与启动参数以 docs/source/guide/storedata.md、docs/source/guide/start.md 为准。
准备条件:Python 版本与环境隔离
文档中对 Python 版本的要求在不同文件里不一致,先核对再动手:
- 仓库根目录的 pyproject.toml 声明
requires-python = ">=3.10,<4",这是源码树自身的依赖清单,从源码安装以此为准; - docs/source/guide/upgrade_community.md 写的是 “Label Studio supports Python 3.9 through 3.13”;
- docs/source/guide/install.md 的 pip 安装一节写 Python 3.8 or later,其引用的系统要求页 docs/source/includes/deploy.md 还写着 Python 3.6 or later。
从源码安装时按仓库清单要求使用 Python 3.10 以上版本最稳妥;版本不匹配可能导致安装报错,这一点在 docs/source/guide/upgrade_community.md 中有明确提示。
Label Studio 要求在干净的 Python 环境中安装,docs/source/guide/install.md 强烈建议用虚拟环境(venv 或 conda)以降低包冲突概率:
python3 -m venv env source env/bin/activate另外注意端口:Label Studio 默认要求 8080 端口开放(docs/source/includes/deploy.md),如需换端口,启动时再指定(见 docs/source/guide/start.md)。
克隆仓库并配置 Python 环境
# 克隆源码仓库 git clone https://gitcode.com/GitHub_Trending/la/label-studio cd label-studio # install dependencies pip install poetry poetry installpoetry install会按 pyproject.toml 安装全部依赖,清单中包含 Django(>=5.2.16,<5.3.0)、psycopg[binary](PostgreSQL 驱动)、label-studio-sdk等。依赖安装完成前,后面的迁移和启动命令无法执行,这一步失败时先解决依赖报错,不要跳过。
迁移数据库:默认 SQLite,可选 PostgreSQL
源码安装文档给出的迁移命令是:
# run db migrations poetry run python label_studio/manage.py migrate默认情况下 Label Studio 使用 SQLite 存储任务和标注数据,不需要额外配置;启动服务后,终端会打印出数据文件所在目录(docs/source/guide/storedata.md)。CONTRIBUTING.md 也确认后端代码需兼容 SQLite 和 PostgreSQL 两种数据库。
如果数据量大(例如导入超过 10 万个任务、5 个以上并发用户),docs/source/guide/storedata.md 建议改用 PostgreSQL。连接 PostgreSQL 需要设置以下环境变量,这组变量及其取值照录自 docs/source/guide/storedata.md,其中POSTGRE_HOST=db是文档原样给出的示例值,请替换为你自己的 PostgreSQL 主机、库名和账号:
export DJANGO_DB=default export POSTGRE_NAME=postgres export POSTGRE_USER=postgres export POSTGRE_PASSWORD=<你的数据库密码> export POSTGRE_PORT=5432 export POSTGRE_HOST=<你的 PostgreSQL 主机>设置后再执行上面的migrate命令,迁移会作用到你指定的数据库。
收集静态文件并启动服务
# collect static files poetry run python label_studio/manage.py collectstatic # start the server in development mode at http://localhost:8080 poetry run python label_studio/manage.py runservercollectstatic对应文档中的 “collect static files” 步骤,runserver以开发模式在http://localhost:8080启动服务(docs/source/guide/install.md)。
验证结果与常见问题
服务启动后,用浏览器打开http://localhost:8080应能看到 Label Studio 页面;文档中源码安装的启动步骤即以该地址作为开发模式地址说明。如果 8080 端口被占用,可参考 docs/source/guide/start.md 中关于指定端口的做法。
几个与源码安装直接相关的边界和后续操作:
- 安装出问题时:docs/source/guide/upgrade_community.md 指向专门的排错文档 docs/source/guide/install_troubleshoot.md。
- 从源码安装后升级版本:docs/source/guide/upgrade_community.md 给出的路径是
git pull(或git fetch --tags+git checkout v1.14.0切到指定版本),然后依次执行poetry install、poetry run python label_studio/manage.py migrate、poetry run python label_studio/manage.py collectstatic,最后poetry run python label_studio/manage.py runserver重启服务。升级前文档要求先备份数据和配置。 - 测试环境注意:跑单元测试时,README.md 示例中通过
DJANGO_DB=sqlite或DJANGO_DB=default区分 SQLite 与 PostgreSQL,迁移前确认环境变量指向的数据库与你的预期一致,避免把迁移写到错误的库上。
【免费下载链接】label-studioLabel Studio is a multi-type data labeling and annotation tool with standardized output format项目地址: https://gitcode.com/GitHub_Trending/la/label-studio
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考