pyinstaller打包web專案

2021-09-11 05:55:53 字數 681 閱讀 7215

pyinstaller打包python非web專案網上資料特別多,但就對於web專案少之又少。

今天在打包python的tornado專案時,出現無法找到靜態檔案和html,但是在非打包時卻執行正常,瀏覽器能夠正常訪問,打包之後就出現這個問題。

查詢相關資料之後發現,-f 這個引數和templates static這兩個的檔案的路徑問題。

-f

這個不建議在web專案打包時使用,因為這個引數雖然使整個專案只有入口檔案,

但是當整個專案執行之後,它會生成乙個臨時檔案,並且這個臨時資料夾是隨機命名的,放在 /tmp/隨機資料夾/ 裡面

有興趣可以使用tornado試試,獲取當前路徑並列印即可。

下面是解決方案,用乙個獲取當前資料夾路徑的方法,獲取templates static的路徑即可,使得專案路徑可以隨時隨地的變化,不受其他因素影響。

def src_path():

if hasattr(sys, '_meipass'):

base_dir = sys._meipass

else:

base_dir = os.path.abspath('.')

return base_dir

剩下的在tornado或者其他python web專案的靜態路徑呼叫該方法就行。

pyinstaller打包程式

python打包成exe檔案時,用的是pyinstaller 第一步安裝pyinstaller pip install pyinstaller第二步 pyinstaller f w i ico py其中 ico 是logo,py是你要打包的py檔案 我在打包時出現了struct.error unpa...

pyinstaller打包使用

pyinstaller manage.py 如果直接打包報錯,使用如下命令可以直接生成配置檔案 pyi makespec d manage.py生成的配置檔案格式如下 mode python coding utf 8 block cipher none a analysis impala etl.p...

pyinstaller 打包總結

pyinstaller 打包過程總結 安裝 pyinstaller 打包工具 pip3 install pyinstallerpyinstaller 打包命令不熟悉的小夥伴可點選這裡檢視喲 備註 以下涉及到的檔案名字main.py,請替換成自己的檔名 執行打包命令生成單獨的 exe 程式 pyins...