日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用pyinstaller打包django3.2

發布時間:2025/1/21 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用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 拷貝過來

datas=[('/Users/huanghuan/Documents/python學習/django/loftyha/static','./static')],hiddenimports=[ 'django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','shift',],

Step 2: 使用pyinstaller 構建可執行文件

pyinstaller manage.spec

待上述命令執行完,在目錄下面會生成dist和build目錄,在dist/manage目錄下,有一個可執行文件manage
cd dist/manage目錄下,命令行執行manage文件

./manage runserver ip:port --noreload

–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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。