使用pyinstaller打包django3.2
生活随笔
收集整理的這篇文章主要介紹了
使用pyinstaller打包django3.2
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用pyinstaller打包django3.2
雖然django項目我們一般通過部署服務器進行發布,但是也有些情況,可能就是一個小小的數據管理應用,也就內部幾個人使用,想直接打包成一個應用,在沒有任何python環境的普通的機器上就能運行,內網能訪問就可以了。
pyinstaller 就能夠用來將python應用打包成可執行文件。
Step 1: 生成spec文件
pyi-makespec -D manage.py執行成功后,會顯示如下信息,表示可以去構建可執行文件了
now run pyinstaller.py to build the executable在目錄下面會生成一個 manage.spec的文件,相當于一個構建可執行文件的配置文件。打開文件,可以看一下,主要有兩個地方需要配置:
1.datas=[] 該配置用于配置static文件和templates文件
hiddenimports=[] 把settings里的install_apps 拷貝過來
Step 2: 使用pyinstaller 構建可執行文件
pyinstaller manage.spec待上述命令執行完,在目錄下面會生成dist和build目錄,在dist/manage目錄下,有一個可執行文件manage
cd dist/manage目錄下,命令行執行manage文件
–noreload參數如果不加,有可能會報錯: RuntimeError(‘Script %s does not exist.’ % py_script)
Traceback (most recent call last):File "manage.py", line 23, in <module>File "manage.py", line 19, in mainFile "django/core/management/__init__.py", line 419, in execute_from_command_lineutility.execute()File "django/core/management/__init__.py", line 413, in executeself.fetch_command(subcommand).run_from_argv(self.argv)File "django/core/management/base.py", line 354, in run_from_argvself.execute(*args, **cmd_options)File "django/core/management/commands/runserver.py", line 61, in executesuper().execute(*args, **options)File "django/core/management/base.py", line 398, in executeoutput = self.handle(*args, **options)File "django/core/management/commands/runserver.py", line 96, in handleself.run(**options)File "django/core/management/commands/runserver.py", line 103, in runautoreload.run_with_reloader(self.inner_run, **options)File "django/utils/autoreload.py", line 640, in run_with_reloaderexit_code = restart_with_reloader()File "PyInstaller/hooks/rthooks/pyi_rth_django.py", line 72, in _restart_with_reloaderFile "django/utils/autoreload.py", line 257, in restart_with_reloaderargs = get_child_arguments()File "django/utils/autoreload.py", line 244, in get_child_argumentsraise RuntimeError('Script %s does not exist.' % py_script)參考鏈接:https://www.jianshu.com/p/8363793b1d41
總結
以上是生活随笔為你收集整理的使用pyinstaller打包django3.2的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ubuntu21.04下VSCode无法
- 下一篇: Django目录结构说明