pyinstaller5.6.2打包django_restframework,simplejwt项目

最新版pyinstaller5.6.2打包django_restframework,simplejwt项目(不含界面只有接口数据)
第一步添加两个hook,放入环境比如D:\Anaconda3\envs\tensorflow2\Lib\site-packages\PyInstaller\hooks
#hook-coreschema.py
from PyInstaller.utils.hooks import collect_data_files, collect_all
hiddenimports = [“coreschema”]
datas = collect_data_files(‘coreschema’)

#hook-mydjango.py
from PyInstaller.utils.hooks import collect_data_files, collect_all
hiddenimports = []
datas = []
binaries = []

datas_rest, binaries_rest, hiddenimports_rest = collect_all(‘rest_framework’)
datas += datas_rest
binaries += binaries_rest
hiddenimports += hiddenimports_rest

第二步在项目根目录下生成manage.spec文件
pyi-makespec -D manage.py

-- mode: python ; coding: utf-8 --

block_cipher = None

a = Analysis(
[‘manage.py’],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[‘common.exceptionHandle’,‘middleware.BaseMiddleWare’,‘rest_framework_simplejwt.state’,‘django.contrib.auth.templatetags’],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

。。。。。。

pyinstaller5.6.2打包django_restframework,simplejwt项目_第1张图片

第三步,修改manage.spec添加hiddenimports内容

-- mode: python ; coding: utf-8 --

block_cipher = None

a = Analysis(
[‘manage.py’],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[‘common.exceptionHandle’,‘middleware.BaseMiddleWare’,‘rest_framework_simplejwt.state’],
hookspath=[],ex
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

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.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name=‘manage’,
)

第四步,打包
pyinstaller manage.spec --noconfirm
第五步启动exe项目
到dist目录下运行
manage.exe runserver 8000 --noreload
pyinstaller5.6.2打包django_restframework,simplejwt项目_第2张图片

你可能感兴趣的:(python,django,软件打包,django,python,后端)