前言
Rye的介绍和安装
Ryehttps://rye.astral.sh/Rye 完整使用教程_安装rye-CSDN博客
https://blog.csdn.net/zhenndbc/article/details/144544692
正文
项目建立
配置好环境后
新建文件夹
新建文件夹,进入项目

初始化
rye init

下载依赖
rye sync

pycharm 打开项目
pycharm .

安装Django
rye add django pyinstaller

在src目录下新建Django项目
django-admin startproject rye_dj

修改文件pyproject.toml文件如下
[project]
name = "rye-dj-demo"
version = "0.1.0"
description = "Add your description here"
authors = [
{ name = "qe-present", email = "2664481691@qq.com" }
]
dependencies = [
"django>=5.1.6",
"pyinstaller>=6.12.0",
]
readme = "README.md"
requires-python = ">= 3.13"
[tool.rye.scripts]
dev= "python manage.py runserver"
build="pyinstaller -F manage.py"
增加了dev脚本和bulid脚本。
进入Django项目。
运行项目


Pyinstaller 打包
暂时什么都不写
rye run build


运行打包后的manage.exe
manage.exe runserver --noreload
笔者是通过powershell 7 运行的命令,有所不同

成功。
Github工作流yaml文件的书写
总体流程
1、读取仓库的代码
2、安装rye
3、安装依赖
4、打包
5、上传
新建相关文件及文件夹
1、在根目录下新建.github文件夹
2、在.github文件夹新建workflows文件夹
3、在workdflows文件夹新建rye-dj.yaml文件

rye-dj.yaml内容如下
name: rye-dj # 工作流程名称
on: push # 触发条件 push触发
jobs:
build: # 任务名称
runs-on: window-latest # 运行环境
steps:
- name: 读取仓库代码
uses: actions/checkout@v4
- name: 安装rye
uses: eifinger/setup-rye@v4
with:
enable-cache: true
version: 'latest'
- name: 安装依赖
run: rye sync
- name: 打包
run: |
cd src/rye_dj
rye run build
- name: 上传
uses: actions/upload-artifact@v4
with:
name: dist
path: src/rye_dj/dist/manage.exe
工作流打包结果


下载运行,项目什么都没有写,因此,没有报错。以后需要配置的项目再写一篇文章。
说明一点
为什么要在src目录下新建Django项目?
亲身实践,如果不这样,会报错,不妨试试。
总结
主要是在rye环境下,github工作流对Django通过pyinstaller进行打包。