Pyinstaller打包

pyinstaller是一个非常简单的打包python的py文件的库,

把py文件打包成exe文件,方便给小白执行程序。

 

官网介绍 http://www.pyinstaller.org/

安装 

pip install pyinstaller

使用PyInstaller生成exe文件

Pyinstaller -F -w -i tk_down.ico test_gui.py

其中tk_down.ico 为图标文件

-F 表示生成单个可执行文件

-w 表示去掉控制台窗口,这在GUI界面时非常有用。

-i 表示可执行文件的图标

 

举例:

(v1) C:\Users\spyider>Pyinstaller -F -w -i tk_down.ico test_gui.py
1788 INFO: PyInstaller: 4.5.1
1789 INFO: Python: 3.6.4 (conda)
1790 INFO: Platform: Windows-7-6.1.7601-SP1
1792 INFO: wrote C:\Users\china\pord_spyider\test_gui.spec
1796 INFO: UPX is not available.
1798 INFO: Extending PYTHONPATH with paths
['C:\\Users\\spyider', 'C:\\Users\\spyider']
2315 INFO: checking Analysis
2393 INFO: checking PYZ
2419 INFO: checking PKG
2420 INFO: Building because toc changed
2421 INFO: Building PKG (CArchive) PKG-00.pkg
6012 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6052 INFO: Bootltestder c:\programdata\anaconda3\lib\site-packages\PyInstaller\boo
tltestder\Windows-32bit\runw.exe
6053 INFO: checking EXE
6054 INFO: Rebuilding EXE-00.toc because test_gui.exe missing
6055 INFO: Building EXE from EXE-00.toc
6058 INFO: Copying icons from ['tk_down.ico']
6069 INFO: Writing RT_GROUP_ICON 0 resource with 20 bytes
6069 INFO: Writing RT_ICON 1 resource with 67624 bytes
6075 INFO: Updating manifest in C:\Users\china\pord_spyider\build\test_gui\runw.ex
e.on_gk_di
6083 INFO: Updating resource type 24 name 1 language 0
6088 INFO: Appending archive to EXE C:\Users\spyider\dist\test_gui.exe
11275 INFO: Building EXE from EXE-00.toc completed successfully.

 

错误解决

  File "c:\programdata\anaconda3\envs\v1\lib\site-packages\PyInstaller\hooks\hook-distutils.py", l
    hiddenimports = [sysconfig._get_sysconfigdata_name()]
TypeError: _get_sysconfigdata_name() missing 1 required positional argument: 'check_exists'

首先,转到python交互式shell,做

$ python
>> import sysconfig
>> print(sysconfig.__file__)

这应该为您提供文件所在的位置sysconfig。然后你需要去那个文件并编辑源代码,

修改了check_exists= True

源文件修改后

def _get_sysconfigdata_name(check_exists= True):
   
    res = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', None)
    if res and check_exists:
        try:
            loader = importlib.util.find_spec(res)
        except:
            res = None
    if res:
        return res
    return '_sysconfigdata_{abi}_{platform}_{multiarch}'.format(
            abi=sys.abiflags,
            platform=sys.platform,
            multiarch=getattr(sys.implementation, '_multiarch', ''))

 

 

  

 

posted @ 2021-11-22 15:59  一只小小的寄居蟹  阅读(891)  评论(0编辑  收藏  举报