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文件

原文地址:https://www.cnblogs.com/yangyangming/p/15673244.html