window python打包py指令碼為exe
阿新 • • 發佈:2021-01-22
window python打包py指令碼為exe
安裝python
依據要求,下載並安裝對應版本,我這裡使用的是python3.7.5;
下載地址:https://www.python.org/ftp/python/3.7.5/python-3.7.5-amd64.exe
備註:首次使用了gz包,接著下pip,結果缺失setuptools,下載setuptools,還是報缺失setuptools,最後放棄了,直接使用exe進行安裝。
安裝pyinstaller
因專案需要,安裝指定版本:pip install pyinstaller==3.6
Collecting pyinstaller==3.6
Downloading https://files.pythonhosted.org/packages/3c/c9/c3f9bc64eb11eee6a824686deba6129884c8cbdf70e750661773b9865ee0/PyInstaller-3.6.tar.gz (3.5MB)
|████████████████████████████████| 3.5MB 234kB/s
Installing build dependencies ... done
Getting requirements to build wheel .. . done
Preparing wheel metadata ... done
Requirement already satisfied: setuptools in c:\python\python37\lib\site-packages (from pyinstaller==3.6) (41.2.0)
Collecting altgraph (from pyinstaller==3.6)
Downloading https://files.pythonhosted.org/packages/ee/3d/bfca21174b162f6ce674953f1b7a640c1498357fa6184776029557c25399/altgraph-0.17-py2.py3-none-any.whl
Collecting pefile>= 2017.8.1 (from pyinstaller==3.6)
Downloading https://files.pythonhosted.org/packages/36/58/acf7f35859d541985f0a6ea3c34baaefbfaee23642cf11e85fe36453ae77/pefile-2019.4.18.tar.gz (62kB)
|████████████████████████████████| 71kB 255kB/s
Collecting pywin32-ctypes>=0.2.0 (from pyinstaller==3.6)
Downloading https://files.pythonhosted.org/packages/9e/4b/3ab2720f1fa4b4bc924ef1932b842edf10007e4547ea8157b0b9fc78599a/pywin32_ctypes-0.2.0-py2.py3-none-any.whl
Collecting future (from pefile>=2017.8.1->pyinstaller==3.6)
Downloading https://files.pythonhosted.org/packages/45/0b/38b06fd9b92dc2b68d58b75f900e97884c45bedd2ff83203d933cf5851c9/future-0.18.2.tar.gz (829kB)
|████████████████████████████████| 829kB 156kB/s
Building wheels for collected packages: pyinstaller
Building wheel for pyinstaller (PEP 517) ... done
Created wheel for pyinstaller: filename=PyInstaller-3.6-cp37-none-any.whl size=2926577 sha256=c4177de83781328795251598ec6cc1533f9e4f2019cb4733bf4b999f44ba0da3
Stored in directory: C:\Users\sun.lee\AppData\Local\pip\Cache\wheels\62\fe\62\4c0f196d1e0dd689e097449bc81d7d585a7de7dd86b081b80b
Successfully built pyinstaller
Installing collected packages: altgraph, future, pefile, pywin32-ctypes, pyinstaller
Running setup.py install for future ... done
Running setup.py install for pefile ... done
Successfully installed altgraph-0.17 future-0.18.2 pefile-2019.4.18 pyinstaller-3.6 pywin32-ctypes-0.2.0
WARNING: You are using pip version 19.2.3, however version 20.3.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
打包
打成exe包:pyinstaller -F xcalbuild.py --hidden-import chardet
82 INFO: PyInstaller: 3.6
82 INFO: Python: 3.7.5
84 INFO: Platform: Windows-10-10.0.18362-SP0
86 INFO: wrote C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\xcalbuild.spec
89 INFO: UPX is not available.
91 INFO: Extending PYTHONPATH with paths
['C:\\Program '
'Files\\xcalclient\\xcalclient-win-1.5.0\\xcalagent\\xcalbuild\\win\\bin',
'C:\\Program '
'Files\\xcalclient\\xcalclient-win-1.5.0\\xcalagent\\xcalbuild\\win\\bin']
91 INFO: checking Analysis
94 INFO: Building because C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\xcalbuild.py changed
95 INFO: Initializing module dependency graph...
98 INFO: Caching module graph hooks...
105 INFO: Analyzing base_library.zip ...
2905 INFO: Caching module dependency graph...
3017 INFO: running Analysis Analysis-00.toc
3020 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\python\python37\python.exe
3338 INFO: Analyzing C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\xcalbuild.py
4154 INFO: Processing module hooks...
4155 INFO: Loading module hook "hook-encodings.py"...
4252 INFO: Loading module hook "hook-pydoc.py"...
4254 INFO: Loading module hook "hook-xml.dom.domreg.py"...
4254 INFO: Loading module hook "hook-xml.py"...
4265 INFO: Looking for ctypes DLLs
4266 INFO: Analyzing run-time hooks ...
4272 INFO: Looking for dynamic libraries
4400 INFO: Looking for eggs
4401 INFO: Using Python library c:\python\python37\python37.dll
4402 INFO: Found binding redirects:
[]
4405 INFO: Warnings written to C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\build\xcalbuild\warn-xcalbuild.txt
4439 INFO: Graph cross-reference written to C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\build\xcalbuild\xref-xcalbuild.html
4448 INFO: checking PYZ
4452 INFO: Building because toc changed
4452 INFO: Building PYZ (ZlibArchive) C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\build\xcalbuild\PYZ-00.pyz
4884 INFO: Building PYZ (ZlibArchive) C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\build\xcalbuild\PYZ-00.pyz completed successfully.
4892 INFO: checking PKG
4893 INFO: Building because toc changed
4894 INFO: Building PKG (CArchive) PKG-00.pkg
6589 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6592 INFO: Bootloader c:\python\python37\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
6592 INFO: checking EXE
6595 INFO: Building because toc changed
6596 INFO: Building EXE from EXE-00.toc
6598 INFO: Appending archive to EXE C:\Program Files\xcalclient\xcalclient-win-1.5.0\xcalagent\xcalbuild\win\bin\dist\xcalbuild.exe
6607 INFO: Building EXE from EXE-00.toc completed successfully.
錯誤處理
1、使用exe安裝包,不然各種問題需要處理
2、一開始安裝了python3.9.1;後面需要更改版本,折騰了半天,以為可以安裝python 直接使用;後面小折騰一下,就重灌了python3.7.5
3、打出exe報錯,沒有找到對應模組:加上匯入即可
–hidden-import chardet