1. 程式人生 > 其它 >pyinstaller打包Django專案

pyinstaller打包Django專案

系統:ubuntu18.04 / Centos 7

自帶Python3.6

1、安裝pip3
apt-get install -y python3-pip
pip3 install --upgrade pip
安裝psycopg2報錯
解決:sudo apt-get install libpq-dev python-dev

2、安裝pyinstaller
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple pyinstaller
進入專案根目錄下執行pyi-makespec -D manage.py,生成manage.spec
3、編輯manage.spec
a = Analysis(['manage.py'],
pathex=[],
binaries=[],
datas=[('/root/projects/installer/GatewayServer/static', './static'), ('/root/projects/installer/GatewayServer/templates', './templates'), ('/root/projects/installer/GatewayServer/conf', './conf')],
hiddenimports=['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'GWS',
'ETGmini',
'DemoGWS',
'repository',
'src.protocolPlugins.base',
'src.protocolPlugins.etgmini',
'src.protocolPlugins.etm100gw',
'src.protocolPlugins.etm100sensor',],
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)

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,
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')

4、執行打包程式(目前只有在centos環境下可以打包成功):pyinstaller manage.spec,生成dist檔案