使用pyinstaller打包django的方法實(shí)現(xiàn)
雖然django項(xiàng)目我們一般通過部署服務(wù)器進(jìn)行發(fā)布,但是也有些情況,可能就是一個小小的數(shù)據(jù)管理應(yīng)用,也就內(nèi)部幾個人使用,想直接打包成一個應(yīng)用,在沒有任何python環(huán)境的普通的機(jī)器上就能運(yù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ù)如果不加,有可能會報(bào)錯: 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的方法實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)pyinstaller打包django內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用python畫出邏輯斯蒂映射(logistic map)中的分叉圖案例
這篇文章主要介紹了使用python畫出邏輯斯蒂映射(logistic map)中的分叉圖案例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12
python學(xué)習(xí)pymongo模塊的使用方法
這篇文章主要介紹了python學(xué)習(xí)pymongo模塊的使用方法,pymongo模塊是python操作mongo數(shù)據(jù)的第三方模塊,總結(jié)一下常用到的簡單用,需要的小伙伴可以參考一下2022-09-09
Python多進(jìn)程multiprocessing用法實(shí)例分析
這篇文章主要介紹了Python多進(jìn)程multiprocessing用法,結(jié)合實(shí)例形式分析了Python多線程的概念以及進(jìn)程的創(chuàng)建、守護(hù)進(jìn)程、終止、退出進(jìn)程、進(jìn)程間消息傳遞等相關(guān)操作技巧,需要的朋友可以參考下2017-08-08
使用Python實(shí)現(xiàn)一個簡單的項(xiàng)目監(jiān)控
這篇文章主要介紹了使用Python實(shí)現(xiàn)一個簡單的項(xiàng)目監(jiān)控,包括連接數(shù)據(jù)庫進(jìn)行查詢等操作,需要的朋友可以參考下2015-03-03
Python學(xué)習(xí)筆記之視頻人臉檢測識別實(shí)例教程
這篇文章主要給大家介紹了關(guān)于Python學(xué)習(xí)筆記之視頻人臉檢測識別的相關(guān)資料,文中通過示例代碼以及圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03

