使用pyinstaller打包django的方法實現(xiàn)
雖然django項目我們一般通過部署服務(wù)器進行發(fā)布,但是也有些情況,可能就是一個小小的數(shù)據(jù)管理應(yīng)用,也就內(nèi)部幾個人使用,想直接打包成一個應(yīng)用,在沒有任何python環(huán)境的普通的機器上就能運行,內(nèi)網(wǎng)能訪問就可以了。
pyinstaller 就能夠用來將python應(yīng)用打包成可執(zhí)行文件。
Step 1: 生成spec文件
pyi-makespec -D manage.py
執(zhí)行成功后,會顯示如下信息,表示可以去構(gòu)建可執(zhí)行文件了
now run pyinstaller.py to build the executable
在目錄下面會生成一個 manage.spec的文件,相當(dāng)于一個構(gòu)建可執(zhí)行文件的配置文件。打開文件,可以看一下,主要有兩個地方需要配置:
1.datas=[] 該配置用于配置static文件和templates文件
hiddenimports=[] 把settings里的install_apps 拷貝過來
datas=[('/Users/huanghuan/Documents/python學(xué)習(xí)/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 構(gòu)建可執(zhí)行文件
pyinstaller manage.spec
待上述命令執(zhí)行完,在目錄下面會生成dist和build目錄,在dist/manage目錄下,有一個可執(zhí)行文件manage
cd dist/manage目錄下,命令行執(zhí)行manage文件
./manage runserver ip:port --noreload
--noreload參數(shù)如果不加,有可能會報錯: 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 main
File "django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "django/core/management/commands/runserver.py", line 61, in execute
super().execute(*args, **options)
File "django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "django/core/management/commands/runserver.py", line 96, in handle
self.run(**options)
File "django/core/management/commands/runserver.py", line 103, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "django/utils/autoreload.py", line 640, in run_with_reloader
exit_code = restart_with_reloader()
File "PyInstaller/hooks/rthooks/pyi_rth_django.py", line 72, in _restart_with_reloader
File "django/utils/autoreload.py", line 257, in restart_with_reloader
args = get_child_arguments()
File "django/utils/autoreload.py", line 244, in get_child_arguments
raise RuntimeError('Script %s does not exist.' % py_script)
到此這篇關(guān)于使用pyinstaller打包django的方法實現(xiàn)的文章就介紹到這了,更多相關(guān)pyinstaller打包django內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python OpenCV 圖像區(qū)域輪廓標記(框選各種小紙條)
這篇文章主要介紹了Python OpenCV 圖像區(qū)域輪廓標記(框選各種小紙條),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03TensorFlow 輸出checkpoint 中的變量名與變量值方式
今天小編就為大家分享一篇TensorFlow 輸出checkpoint 中的變量名與變量值方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02Python基礎(chǔ)之列表常見操作經(jīng)典實例詳解
這篇文章主要介紹了Python基礎(chǔ)之列表常見操作,結(jié)合實例形式詳細分析了Python列表創(chuàng)建方式、內(nèi)置函數(shù)與相關(guān)使用技巧,需要的朋友可以參考下2020-02-02django數(shù)據(jù)庫遷移migration實現(xiàn)
這篇文章主要介紹了django數(shù)據(jù)庫遷移migration實現(xiàn),遷移任務(wù)是根據(jù)對models.py文件的改動情況,添加或者刪除表和列,下面詳細的相關(guān)內(nèi)容需要的小伙伴可以參考一下2022-02-02