Windows 11 部署 本地Dify步骤

Windows 11 部署 本地Dify步骤

前置要求

Python 3.12

地址:https://www.python.org/downloads/

注意:设置path变量

Node.js 18+

地址:https://nodejs.org/zh-cn/download

注意:npm config set registry https://registry.npmmirror.com

PostgreSQL 14+

地址: https://www.postgresql.org/download/windows/

注意:设置的超级用户密码

Redis for Windows7.2

地址:https://codeload.github.com/zkteco-home/redis-windows/zip/refs/tags/7.2.4

注意:默认没设置密码,后续dity/api的env配置要修改REDIS_USERNAME=、REDIS_PASSWORD= 、CELERY_BROKER_URL=redis://localhost:6379/0

Git:

https://git-scm.com/downloads

注意:目前25年3月 1.0版本dity bug较多,注意切换dity分支到0.15.2 或0.15.3

Ollama (可选,用于本地模型) 本地跑模型除非机器特别好否则不建议

依赖列表

新增requirements.txt,加到dity/api下

bash 复制代码
# requirements.txt
anthropic==0.23.1
authlib==1.3.1
azure-ai-inference==1.0.0b8
azure-ai-ml==1.20.0
azure-identity==1.16.1
beautifulsoup4==4.12.2
boto3==1.36.12
bs4==0.0.1
cachetools==5.3.0
celery==5.4.0
chardet==5.1.0
cohere==5.2.4
dashscope[tokenizer]==1.17.0
fal-client==0.5.6
flask==3.1.0
flask-compress==1.17
flask-cors==4.0.0
flask-login==0.6.3
flask-migrate==4.0.7
flask-restful==0.3.10
flask-sqlalchemy==3.1.1
gevent==24.11.1
gmpy2==2.2.1
google-ai-generativelanguage==0.6.9
google-api-core==2.18.0
google-api-python-client==2.90.0
google-auth==2.29.0
google-auth-httplib2==0.2.0
google-cloud-aiplatform==1.49.0
google-generativeai==0.8.1
googleapis-common-protos==1.63.0
gunicorn==23.0.0
httpx[socks]==0.27.0
huggingface-hub==0.16.4
jieba==0.42.1
langfuse==2.51.3
langsmith==0.1.77
mailchimp-transactional==1.0.50
markdown==3.5.1
nomic==3.1.2
novita-client==0.5.7
numpy==1.26.4
oci==2.135.1
openai==1.61.0
openpyxl==3.1.5
opik==1.3.4
pandas[performance,excel]==2.2.2
pandas-stubs==2.2.3.241009
psycogreen==1.0.2
psycopg2-binary==2.9.6
pycryptodome==3.19.1
pydantic==2.9.2
pydantic-settings==2.6.0
pydantic_extra_types==2.9.0
pyjwt==2.8.0
pypdfium2==4.30.0
python-docx==1.1.0
python-dotenv==1.0.1
pyyaml==6.0.1
readabilipy==0.2.0
redis[hiredis]==5.0.3
replicate==0.22.0
resend==0.7.0
sagemaker==2.231.0
scikit-learn==1.5.1
sentry-sdk[flask]==1.44.1
sqlalchemy==2.0.29
starlette==0.41.0
tencentcloud-sdk-python-hunyuan==3.0.1294
tiktoken==0.8.0
tokenizers==0.15.0
transformers==4.35.0
unstructured[docx,epub,md,msg,ppt,pptx]==0.16.1
validators==0.21.0
volcengine-python-sdk[ark]==1.0.98
websocket-client==1.7.0
xinference-client==0.15.2
yarl==1.18.3
youtube-transcript-api==0.6.2
zhipuai==2.1.5

# Indirect Dependencies
kaleido==0.2.1
rank-bm25==0.2.2
safetensors==0.4.3

# Tools Dependencies
arxiv==2.1.0
cloudscraper==1.2.71
duckduckgo-search==6.3.0
jsonpath-ng==1.6.1
matplotlib==3.8.2
mplfonts==0.0.8
newspaper3k==0.2.8
nltk==3.9.1
numexpr==2.9.0
pydub==0.25.1
qrcode==7.4.2
twilio==9.0.4
vanna[postgres,mysql,clickhouse,duckdb,oracle]==0.7.5
wikipedia==1.4.0
yfinance==0.2.40

# Storage Dependencies
azure-storage-blob==12.13.0
bce-python-sdk==0.9.23
cos-python-sdk-v5==1.9.30
esdk-obs-python==3.24.6.1
google-cloud-storage==2.16.0
opendal==0.45.12
oss2==2.18.5
supabase==2.8.1
tos==2.7.1

# Vector Database Dependencies
alibabacloud_gpdb20160503==3.8.0
alibabacloud_tea_openapi==0.3.9
chromadb==0.5.20
clickhouse-connect==0.7.16
couchbase==4.3.0
elasticsearch==8.14.0
opensearch-py==2.4.0
oracledb==2.2.1
pgvecto-rs[sqlalchemy]==0.2.1
pgvector==0.2.5
pymilvus==2.5.0
pymochow==1.3.1
pyobvector==0.1.6
qdrant-client==1.7.3
tcvectordb==1.3.2
tidb-vector==0.0.9
upstash-vector==0.6.0
volcengine-compat==1.0.156
weaviate-client==3.21.0

# Development Dependencies
coverage==7.2.4
faker==32.1.0
mypy==1.13.0
pytest==8.3.2
pytest-benchmark==4.0.0
pytest-env==1.1.3
pytest-mock==3.14.0
types-beautifulsoup4==4.12.0.20241020
types-flask-cors==5.0.0.20240902
types-flask-migrate==4.1.0.20250112
types-html5lib==1.1.11.20241018
types-openpyxl==3.1.5.20241225
types-protobuf==5.29.1.20241207
types-psutil==6.1.0.20241221
types-psycopg2==2.9.21.20250121
types-python-dateutil==2.9.0.20241206
types-pytz==2024.2.0.20241221
types-pyyaml==6.0.12.20241230
types-regex==2024.11.6.20241221
types-requests==2.32.0.20241016
types-six==1.17.0.20241205
types-tqdm==4.67.0.20241221

# Linting Dependencies
dotenv-linter==0.5.0
ruff==0.9.2

下载并配置 Dify

bash 复制代码
# 克隆项目
git clone https://gitee.com/dify_ai/dify.git
#进入项目api目录
cd dify
cd api
#创建python 虚拟环境
python -m venv venv
#激活虚拟环境,激活成功候命令行最前面会出现:(venv)c:\dify\api
.\venv\Scripts\activate
# 检查 Python 路径
where python
# 应显示: C:\path\to\dify\api\venv\Scripts\python.exe

# 更新 pip
python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装基础依赖
pip install wheel setuptools -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装项目依赖,报错很正常,根据报错日志修改requirements中的包版本或者安装预编译版本
# 使用预编译包 pip install 包名 --only-binary :all:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 安装 PyTorch 和 AI 相关依赖
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install transformers accelerate optimum -i https://pypi.tuna.tsinghua.edu.cn/simple

配置dity启动环境

bash 复制代码
# 复制环境配置文件
cp .env.example .env

可以直接打开env修改以下配置:

bash 复制代码
DB_USERNAME=postgres
DB_PASSWORD=你的PostgreSQL密码
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=dify
#redis如果默认为空这里设置为空
REDIS_USERNAME=
REDIS_PASSWORD=
CELERY_BROKER_URL=redis://localhost:6379/0
OLLAMA_API_BASE_URL=http://localhost:11434
OLLAMA_PROXY_API_KEY=your_key_here

初始化数据库

bash 复制代码
# 创建数据库
psql -U postgres
CREATE DATABASE dify;
\q

在api目录执行

bash 复制代码
# 初始化数据库架构
flask db upgrade
flask init

安装前端依赖

bash 复制代码
# 切换到前端目录
cd ..\web

# 安装依赖
npm install

# 复制前端环境配置
copy .env.example .env.local

启动服务

javascript 复制代码
# 终端 1 - 启动后端 (在 api 目录下)
# 确保激活了虚拟环境 (venv)
flask run --debug --host 0.0.0.0 --port 5001

# 终端 2 - 启动前端 (在 web 目录下)
npm run dev

验证

bash 复制代码
访问 http://localhost:3000
默认管理员账号:admin@foo.bar
默认密码:12345678

问题检查

服务启动检查:

PostgreSQL 服务是否运行

Redis 服务是否运行

虚拟环境是否激活

.env 配置是否正确

日志查看:

后端日志:api/logs/

使用 debug 模式:flask run --debug

Dify Backend API 安装与运行

注意要进入目录api

bash 复制代码
# 安装 Poetry
pip install poetry

# 安装 Poetry shell 插件
poetry self add poetry-plugin-shell

# 指定 Python 版本
poetry env use 3.12

# 安装项目依赖
poetry install

数据迁移

bash 复制代码
poetry run python -m flask db upgrade

服务启动:

bash 复制代码
# 启动后端服务
poetry run python -m flask run --host 0.0.0.0 --port=5001 --debug

启动异步任务:

bash 复制代码
poetry run python -m celery -A app.celery worker \
    -P gevent -c 1 \
    --loglevel INFO \
    -Q dataset,generation,mail,ops_trace,app_deletion
相关推荐
noravinsc几秒前
python 提取视频中的音频
开发语言·python·音视频
潘达斯奈基~13 分钟前
万字总结数据分析思维
数据库·python·数据分析
站大爷IP38 分钟前
基于Python的情感分析与情绪识别技术深度解析
python
zzlyx9942 分钟前
Manus(一种AI代理或自动化工具)与DeepSeek(一种强大的语言模型或AI能力)结合使用任务自动化和智能决策
人工智能·语言模型·自动化
CodeCraft Studio1 小时前
word处理控件Aspose.Words教程:使用 Python 删除 Word 中的空白页
开发语言·python·word
查理零世1 小时前
【蓝桥杯集训·每日一题2025】 AcWing 5590. 沿栅栏散步 python
python·算法·蓝桥杯
孔令飞2 小时前
11 | 给 Gin 服务器添加中间件
人工智能·ai·云原生·golang·kubernetes
long_songs2 小时前
《用Python+PyGame开发双人生存游戏!源码解析+完整开发思路分享》
python·游戏·pycharm·pygame
m0_748235072 小时前
Python高级之操作Mysql
python·mysql·adb
摸鱼小天才2 小时前
提示词工程——AI应用必不可少的技术
ai·大模型