用pyinstaller打包exe注意事項

以下環(huán)境為python3.6.5, 在virtualenv下實現(xiàn)

  1. pyinstaller采用3.3.1版本

    pip install pyinstaller==3.3.1

  2. setuptools采用44.0.0版本

    pip install setuptools==44.0.0

  3. 由于依賴了crypto庫用于加密惋嚎,但是pyinstaller庫延續(xù)開發(fā)的人漏了hook杠氢,需要手動加一個hook文件到C:\python36\Lib\site-packages\PyInstaller\hooks,文件名是hook-Crypto.py另伍,內(nèi)容如下:

    
    #-----------------------------------------------------------------------------
    # Copyright (c) 2005-2018, PyInstaller Development Team.
    #
    # Distributed under the terms of the GNU General Public License with exception
    # for distributing bootloader.
    #
    # The full license is in the file COPYING.txt, distributed with this software.
    #-----------------------------------------------------------------------------
     
    """
    Hook for PyCryptodome library: https://pypi.python.org/pypi/pycryptodome
    PyCryptodome is an almost drop-in replacement for the now unmaintained
    PyCrypto library. The two are mutually exclusive as they live under
    the same package ("Crypto").
    PyCryptodome distributes dynamic libraries and builds them as if they were
    Python C extensions (even though they are not extensions - as they can't be
    imported by Python). It might sound a bit weird, but this decision is rooted
    in PyPy and its partial and slow support for C extensions. However, this also
    invalidates several of the existing methods used by PyInstaller to decide the
    right files to pull in.
    Even though this hook is meant to help with PyCryptodome only, it will be
    triggered also when PyCrypto is installed, so it must be tested with both.
    Tested with PyCryptodome 3.5.1, PyCrypto 2.6.1, Python 2.7 & 3.6, Fedora & Windows
    """
     
    import os
    import glob
     
    from PyInstaller.compat import EXTENSION_SUFFIXES
    from PyInstaller.utils.hooks import get_module_file_attribute
     
    # Include the modules as binaries in a subfolder named like the package.
    # Cryptodome's loader expects to find them inside the package directory for
    # the main module. We cannot use hiddenimports because that would add the
    # modules outside the package.
     
    binaries = []
    binary_module_names = [
        'Crypto.Math',      # First in the list
        'Crypto.Cipher',
        'Crypto.Util',
        'Crypto.Hash',
        'Crypto.Protocol',
    ]
     
    try:
        for module_name in binary_module_names:
            m_dir = os.path.dirname(get_module_file_attribute(module_name))
            for ext in EXTENSION_SUFFIXES:
                module_bin = glob.glob(os.path.join(m_dir, '_*%s' % ext))
                for f in module_bin:
                    binaries.append((f, module_name.replace('.', os.sep)))
    except ImportError:
        # Do nothing for PyCrypto (Crypto.Math does not exist there)
        pass
    
  4. 執(zhí)行打包命令

    pyinstaller main.py -F -p C:\..\venv\Lib\site-packages
    
  5. 附上requirement.txt

    altgraph==0.17
    certifi==2019.11.28
    cffi==1.14.0
    chardet==3.0.4
    cryptography==2.8
    future==0.18.2
    idna==2.8
    macholib==1.14
    Naked==0.1.31
    pefile==2019.4.18
    pycparser==2.19
    pycryptodome==3.9.6
    PyInstaller==3.3.1
    pywin32-ctypes==0.2.0
    PyYAML==5.3
    requests==2.22.0
    shellescape==3.8.1
    six==1.14.0
    urllib3==1.25.8
    
    

    ?

?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末鼻百,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子质况,更是在濱河造成了極大的恐慌,老刑警劉巖玻靡,帶你破解...
    沈念sama閱讀 219,539評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件结榄,死亡現(xiàn)場離奇詭異,居然都是意外死亡囤捻,警方通過查閱死者的電腦和手機臼朗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,594評論 3 396
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來蝎土,“玉大人视哑,你說我怎么就攤上這事√苎模” “怎么了挡毅?”我有些...
    開封第一講書人閱讀 165,871評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長暴构。 經(jīng)常有香客問我跪呈,道長,這世上最難降的妖魔是什么取逾? 我笑而不...
    開封第一講書人閱讀 58,963評論 1 295
  • 正文 為了忘掉前任耗绿,我火速辦了婚禮,結果婚禮上砾隅,老公的妹妹穿的比我還像新娘误阻。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 67,984評論 6 393
  • 文/花漫 我一把揭開白布究反。 她就那樣靜靜地躺著寻定,像睡著了一般。 火紅的嫁衣襯著肌膚如雪奴紧。 梳的紋絲不亂的頭發(fā)上特姐,一...
    開封第一講書人閱讀 51,763評論 1 307
  • 那天,我揣著相機與錄音黍氮,去河邊找鬼唐含。 笑死,一個胖子當著我的面吹牛沫浆,可吹牛的內(nèi)容都是我干的捷枯。 我是一名探鬼主播,決...
    沈念sama閱讀 40,468評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼专执,長吁一口氣:“原來是場噩夢啊……” “哼淮捆!你這毒婦竟也來了?” 一聲冷哼從身側響起本股,我...
    開封第一講書人閱讀 39,357評論 0 276
  • 序言:老撾萬榮一對情侶失蹤攀痊,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后拄显,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體苟径,經(jīng)...
    沈念sama閱讀 45,850評論 1 317
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,002評論 3 338
  • 正文 我和宋清朗相戀三年躬审,在試婚紗的時候發(fā)現(xiàn)自己被綠了棘街。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,144評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡承边,死狀恐怖遭殉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情博助,我是刑警寧澤险污,帶...
    沈念sama閱讀 35,823評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站富岳,受9級特大地震影響罗心,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜城瞎,卻給世界環(huán)境...
    茶點故事閱讀 41,483評論 3 331
  • 文/蒙蒙 一渤闷、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧脖镀,春花似錦飒箭、人聲如沸狼电。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,026評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽肩碟。三九已至,卻和暖如春凸椿,著一層夾襖步出監(jiān)牢的瞬間削祈,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,150評論 1 272
  • 我被黑心中介騙來泰國打工脑漫, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留髓抑,地道東北人。 一個月前我還...
    沈念sama閱讀 48,415評論 3 373
  • 正文 我出身青樓优幸,卻偏偏與公主長得像吨拍,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子网杆,可洞房花燭夜當晚...
    茶點故事閱讀 45,092評論 2 355

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