当前位置: 首页 > news >正文

记录一下 在Mac下用pyinstallter 打包 Django项目

安装:

pip install pyinstaller 

在urls.py


from SheepMasterOneToOne import settings
from django.conf.urls.static import staticurlpatterns = [path("admin/", admin.site.urls),path('generate_report/export/', ReportAdmin(models.Report, admin.site).generate_report, name='generate_report'),]if settings.DEBUG:urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

在settings.py


STATIC_URL = "static/"STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

收集静态文件

python manage.py collectstatic 

在项目根目录下

# 二者选其一
pyinstaller --onefile manage.py pyi-makespec -D manage.py  

生成

如果报错就修改manage.spec


# -*- mode: python ; coding: utf-8 -*-a = Analysis(['manage.py'],pathex=[],binaries=[],datas=[# 自己的模版 打包后的存放路径('templates/admin/*', 'templates/admin'),# 收集的静态文件 -> 打包后的存放路径('staticfiles','static'),# 第三方app的静态文件('/path/to/yourproject/venv/lib/python3.9/site-packages/simpleui/static','simpleui/static'),# # 第三方app的模版文件('/path/to/yourproject/venv/lib/python3.9/site-packages/simpleui/templates','simpleui/templates'),],# 注册的 app hiddenimports=["simpleui","django.contrib.admin","django.contrib.auth","django.contrib.contenttypes","django.contrib.sessions","django.contrib.messages","django.contrib.staticfiles","sheep.apps.SheepConfig",'sheep.apps'],hookspath=[],hooksconfig={},runtime_hooks=[],excludes=[],noarchive=False,optimize=0,)pyz = PYZ(a.pure)exe = EXE(pyz,a.scripts,[],exclude_binaries=True,name='manage',debug=False,bootloader_ignore_signals=False,strip=False,upx=True,console=True,disable_windowed_traceback=False,argv_emulation=False,target_arch=None,codesign_identity=None,entitlements_file=None,)coll = COLLECT(exe,a.binaries,a.datas,strip=False,upx=True,upx_exclude=[],name='manage',
)

 

修改以后 执行 pyinstaller manage.spec  重新打包

pyinstaller manage.spec 

打包成功 最后运行 

./dist/manage runserver 8080 --noreload

 启动成功

 

http://www.lryc.cn/news/533687.html

相关文章:

  • 【漫话机器学习系列】084.偏差和方差的权衡(Bias-Variance Tradeoff)
  • deepseek本地部署-linux
  • 解决使用python提取word文档中所有的图片时图片丢失的问题
  • 【Spring相关知识】Spring应用如何优雅使用消息队列
  • 人工智能:从概念到未来
  • CUDA Graph
  • 1343. 大小为 K 且平均值大于等于阈值的子数组数目
  • IDEA+DeepSeek让Java开发起飞
  • C# winforms 使用菜单和右键菜单
  • IDEA编写SpringBoot项目时使用Lombok报错“找不到符号”的原因和解决
  • C基础寒假练习(6)
  • 【论文翻译】DeepSeek-V3论文翻译——DeepSeek-V3 Technical Report——第一部分:引言与模型架构
  • 【docker】Failed to allocate manager object, freezing:兼容兼容 cgroup v1 和 v2
  • 我使用deepseek高效学习-分析外文网站Cron定时执行任务
  • Android13-系统服务大管家-ServiceManager进程-启动篇
  • 论文笔记:Rethinking Graph Neural Networks for Anomaly Detection
  • vue知识补充
  • pushgateway指标聚合问题
  • 使用docker搭建FastDFS文件服务
  • 【R语言】数据分析
  • 蓝桥杯C语言组:图论问题
  • jmeter 性能测试Linux 常用的安装
  • 19 角度操作模块(angle.rs)
  • 前端高级面试题及其答案
  • 【ORACLE】这个‘‘和null不等价的场景,deepseek你怎么看?
  • 使用Python实现PDF与SVG相互转换
  • ComfyUI 安装教程:macOS 和 Linux 统一步骤
  • 360手机刷机 360手机解Bootloader 360手机ROOT
  • t113-qt
  • 【真一键部署脚本】——一键部署deepseek