pyinstaller踩坑記

基本命令

pip install pyinstaller
cmd里面進(jìn)入jobs2.py所在的文件夾需忿。
pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" jobs2.py
上面的-w選項(xiàng)是去掉運(yùn)行時的cmd窗口藏斩,--add-data選項(xiàng)是打包非python代碼文件進(jìn)去, -F代表編譯為單個exe文件撒妈。

坑: PyQt5報錯

Exception:

        Cannot find existing PyQt5 plugin directories

        Paths checked: C:/Miniconda3/conda-bld/qt_1535195524645/_h_env/Library/plugins

方案: pip install PyQt5
網(wǎng)上說法:
Unfortunately, conda's version of PyQt5 is broken -- it returns invalid paths when querying QLibraryInfo. The pip-installed version would work fine.
@roynielsen17, you're correct that Python 2.7 is supported until 2020; Pyinstaller will support Python 2.7 until that date as well. However, PyQt5 doesn't support Python 2.7 -- that's the core roadblock.

|

坑: 安裝的時候出現(xiàn)permission error

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: 'd:\programdata\anaconda3\Lib\site-packages\PyQt5\Qt\bin\d3dcompiler_47.dll'
Consider using the --user option or check the permissions.
方案: 使用虛擬環(huán)境來安裝
D:\GoogleDrive\2_2017Dev\Py\yescript\runcodedesign>activate base
(base) D:\GoogleDrive\2_2017Dev\Py\yescript\runcodedesign>pip install PyQt5

網(wǎng)上大神的說法:
You are trying to install the package to a system folder which you don't have permissions to write to.
You have three options(use only one of them):
1-setup a virtual env to install the package (recommended):
python3 -m venv env
source ./env/bin/activate
python -m pip install google-assistant-sdk[samples]
2-Install the package to the user folder:
python -m pip install --user google-assistant-sdk[samples]
3-use sudo to install to the system folder (not recommended)
sudo python -m pip install google-assistant-sdk[samples]

坑: 運(yùn)行jobs.exe 報TemplateNotFound錯誤

這一類問題都是找不到所需要的文件。一般都需要把文件附帶上去,同時重新設(shè)計相對路徑困肩。參考說明
pyinstaller -w -F --add-data "templates;templates" --add-data "static;static" jobs.py
方案:需要把下面的邏輯加上去整陌。sys._MEIPASS是exe在運(yùn)行時候的目錄拗窃。

if getattr(sys, 'frozen', False):
  template_folder = os.path.join(sys._MEIPASS, 'templates') #sys._MEIPASS is a temporary folder for PyInstaller
  app = Flask(__name__, template_folder=template_folder)
else:
  app = Flask(__name__)

坑: mutiprocess打包之后不停執(zhí)行,導(dǎo)致內(nèi)存溢出

解決方案:

if __name__ == '__main__':
    multiprocessing.freeze_support()
    # my code

網(wǎng)上大神:
The reason is lack of fork() on Windows (which is not entirely true). Because of this, on Windows the fork is simulated by creating a new process in which code, which on Linux is being run in child process, is being run. As the code is to be run in technically unrelated process, it has to be delivered there before it can be run. The way it's being delivered is first it's being pickled and then sent through the pipe from the original process to the new one. In addition this new process is being informed it has to run the code passed by pipe, by passing --multiprocessing-fork command line argument to it. If you take a look at implementation of freeze_support() function its task is to check if the process it's being run in is supposed to run code passed by pipe or not.

坑: 引入six的時候會報錯

升級setuptools
pip install --upgrade setuptools

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末泌辫,一起剝皮案震驚了整個濱河市随夸,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌震放,老刑警劉巖宾毒,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異殿遂,居然都是意外死亡诈铛,警方通過查閱死者的電腦和手機(jī)乙各,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來幢竹,“玉大人耳峦,你說我怎么就攤上這事》镣耍” “怎么了妇萄?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長咬荷。 經(jīng)常有香客問我冠句,道長,這世上最難降的妖魔是什么幸乒? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任懦底,我火速辦了婚禮,結(jié)果婚禮上罕扎,老公的妹妹穿的比我還像新娘聚唐。我一直安慰自己,他們只是感情好腔召,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布杆查。 她就那樣靜靜地躺著,像睡著了一般臀蛛。 火紅的嫁衣襯著肌膚如雪亲桦。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天浊仆,我揣著相機(jī)與錄音客峭,去河邊找鬼。 笑死抡柿,一個胖子當(dāng)著我的面吹牛舔琅,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播洲劣,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼备蚓,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了囱稽?” 一聲冷哼從身側(cè)響起星著,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎粗悯,沒想到半個月后虚循,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年横缔,在試婚紗的時候發(fā)現(xiàn)自己被綠了铺遂。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡茎刚,死狀恐怖襟锐,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情膛锭,我是刑警寧澤粮坞,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站初狰,受9級特大地震影響莫杈,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜奢入,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一筝闹、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧腥光,春花似錦关顷、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽捉片。三九已至平痰,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間界睁,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工兵拢, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留翻斟,地道東北人。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓说铃,卻偏偏與公主長得像访惜,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子腻扇,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,601評論 2 353

推薦閱讀更多精彩內(nèi)容