Python安裝pyinstaller方法,以及將項目生成可執行程序的步驟


pyinstaller安裝方法

前提:確保計算機安裝了Python語言環境,並且正確配置了環境變量。

方法一:聯網在線自動安裝

選擇一 Windows OS下進入cmd(命令行窗口) 輸入:pip install pyinstaller

選擇二 在Pycharm IDE 終端下 輸入:pip install pyinstaller

 

 

我在Pycharm 終端下安裝pyinstaller時,遇到這樣的安裝錯誤:

D:\pycharm-workspace>pip install pyinstaller
Collecting pyinstaller
Using cached https://files.pythonhosted.org/packages/03/32/0e0de593f129bf1d1e77eed562496d154ef4460fd5cecfd78612ef39a0cc/PyInstaller-3.4.tar.gz
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... error
ERROR: Complete output from command 'd:\python\python.exe' 'd:\python\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\林芝\AppData\Local\Temp\tmpjsdjh2mc':
ERROR: running dist_info
creating C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info
writing C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\PKG-INFO
writing dependency_links to C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\dependency_links.txt
writing entry points to C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\entry_points.txt
writing requirements to C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\requires.txt
writing top-level names to C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\top_level.txt
writing manifest file 'C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\SOURCES.txt'
reading manifest file 'C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
Error in sitecustomize; set PYTHONVERBOSE for traceback:
SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xc1 in position 0: invalid start byte (sitecustomize.py, line 21)
no previously-included directories found matching 'bootloader\build'
no previously-included directories found matching 'bootloader\.waf-*'
no previously-included directories found matching 'bootloader\.waf3-*'
no previously-included directories found matching 'bootloader\waf-*'
no previously-included directories found matching 'bootloader\waf3-*'
no previously-included directories found matching 'bootloader\_sdks'
no previously-included directories found matching 'bootloader\.vagrant'
warning: no previously-included files found matching 'bootloader\.lock-waf*'
no previously-included directories found matching 'doc\source'
no previously-included directories found matching 'doc\_build'
warning: no previously-included files matching '*.tmp' found under directory 'doc'
warning: no files found matching 'news\_template.rst'
no previously-included directories found matching 'news'
no previously-included directories found matching 'old'
no previously-included directories found matching 'scripts'
no previously-included directories found matching 'tests\scripts'
no previously-included directories found matching '.github'
warning: no previously-included files found matching '.*'
warning: no previously-included files found matching '*.yml'
warning: no previously-included files found matching '*~'
warning: no previously-included files found matching '.directory'
writing manifest file 'C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.egg-info\SOURCES.txt'
creating 'C:\Users\林芝\AppData\Local\Temp\pip-install-_cg8f619\pyinstaller\pip-wheel-metadata\PyInstaller.dist-info'
error: invalid command 'bdist_wheel'
----------------------------------------
ERROR: Command "'d:\python\python.exe' 'd:\python\lib\site-packages\pip\_vendor\pep517\_in_process.py' prepare_metadata_for_build_wheel 'C:\Users\林芝\AppData\Local\Temp\tmpjsdjh2mc'" failed with error code 1 in C:\Users\林芝\
AppData\Local\Temp\pip-install-_cg8f619\pyinstaller

 

######################## 終端提示我 命令執行失敗,錯誤代碼1  我也不知道這種方法安裝失敗的原因, 歡迎大家交流討論#######################

 

方法二:自主下載pyinstaller包,進行手動安裝

pyinstaller 的下載地址:http://www.pyinstaller.org/downloads.html

 

下載文件后,解壓文件。

我的解壓路徑是:  D:\python\pyinstaller-pyinstaller-d740524

windows OS cmd(命令行窗口)進入 解壓文件所在的目錄。

cd D:\python\pyinstaller-pyinstaller-d740524

D:\

輸入: python setup.py install

等待一段時間,pyinstaller就會安裝成功

 

安裝成功后,查看一下pyinstaller的版本信息

pyinstaller --version

出現結果如下,證明安裝成功!

 

Python項目生成可執行程序的步驟

選擇一:Windows OS下進入cmd(命令行窗口) 輸入:pyinstaller -F xx.py xxx.py ......

選擇二:在Pycharm IDE 終端下 輸入:pyinstaller -F xx.py xxx.py ......

xx.py 和 xxx.py 是要打包的文件名

-F參數的含義是,將多個.py腳本文件打包成為一個可執行程序。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM