對於那些網絡比較穩定,可以流暢使用pip源地址的用戶,直接下面的命令就能夠搞定:python
pip install pyinstaller
一般咱們會下載源碼包,而後進入包目錄,執行下面的命令(須要安裝setuptools):git
python setup.py install
對於其餘安裝選項,請參閱手冊和PIP用戶指南。github
安裝當前開發版本使用:網絡
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.tar.gz
安裝完後,檢查安裝成功與否:app
pyinstaller --version
安裝成功後,就可使用下面的命令了:post
pyinstaller
: 打包可執行文件的主要命令,詳細用法下面會介紹。pyi-archive_viewer
: 查看可執行包裏面的文件列表。pyi-bindepend
: 查看可執行文件依賴的動態庫(.so或.dll文件)pyi-...
: 等等。在執行pyInstaller
命令的時候,會在和腳本相同目錄下,生成一個.spec
文件,該文件會告訴pyinstaller如何處理你的全部腳本,同時包含了命令選項。通常咱們不用去理會這個文件,若須要打包數據文件,或者給打包的二進制增長一些Python的運行時選項時...一些高級打包選項時,須要手動編輯.spec
文件。可使用:ui
pyi-makespec options script [script ...]
pyinstaller
的語法:spa
pyinstaller [options] script [script ...] | specfile
最簡單的用法,在和myscript.py同目錄下執行命令:操作系統
pyinstaller mycript.py
而後會看到新增長了兩個目錄build和dist,dist下面的文件就是能夠發佈的可執行文件,對於上面的命令你會發現dist目錄下面有一堆文件,各類都動態庫文件和myscrip可執行文件。有時這樣感受比較麻煩,須要打包dist下面的全部東西才能發佈,萬一丟掉一個動態庫就沒法運行了,好在pyInstaller支持單文件模式,只須要執行:code
pyinstaller -F mycript.py
你會發現dist下面只有一個可執行文件,這個單文件就能夠發佈了,能夠運行在你正在使用的操做系統相似的系統的下面。
若是python不是默認安裝路徑,可能會找不到相應的庫文件:
Traceback (most recent call last): File "/xs/app/python3.5/bin/pyinstaller", line 11, in <module> sys.exit(run()) File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/__main__.py", line 94, in run run_build(pyi_config, spec_file, **vars(args)) File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/__main__.py", line 46, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 791, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 737, in build exec(text, spec_namespace) File "<string>", line 16, in <module> File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 213, in __init__ self.__postinit__() File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/datastruct.py", line 161, in __postinit__ self.assemble() File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 545, in assemble self._check_python_library(self.binaries) File "/xs/app/python3.5/lib/python3.5/site-packages/PyInstaller/building/build_main.py", line 629, in _check_python_library raise IOError(msg) OSError: Python library not found: libpython3.5mu.so.1.0, libpython3.5.so.1.0, libpython3.5m.so.1.0 This would mean your Python installation doesn't come with proper library files. This usually happens by missing development package, or unsuitable build parameters of Python installation. * On Debian/Ubuntu, you would need to install Python development packages * apt-get install python3-dev * apt-get install python-dev * If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)
解決方法:
1.編譯/etc/ld.so.conf,添加: /usr/local/lib64 /usr/local/lib 2.ldconfig 3.從新pyinstaller文件便可