当前位置:   article > 正文

python转exe的问题_liunx系统systemerror: py_ssize_t_clean macro must be

liunx系统systemerror: py_ssize_t_clean macro must be defined for '#' formats

python程序打包成exe后遇到的问题

之前一直都是用的家里的电脑用pyinstaller打包的,今天为了方便准备在公司离线的环境下安装pyinstaller的依赖包。
目前在CSDN上找到的两个文件

pyinstaller安装所需文件及其依赖.rar
PyInstaller-3.6-py2.py3-none-any.whl
  • 1
  • 2

RAR文件中,Pyinstaller文件无法使用,因此在站内又找了whl文件
安装完成依赖包之后,可以对python进行打包,但exe文件无法使用,以下是操作步骤

首先要说明的是,我的python程序中涉及sys.argv,并且在命令行中运行python程序,可以运行,运行代码和结果如下(为保密我删掉了python程序的路径,将python名称改为test.py,希望不要在意)

D:\>python text.py "D:\xxxx(某文件)" "D:\xxxx(某文件)"
D:\text.py:2: DeprecationWarning: The asyncore module is deprecated and will be removed in Python 3.12. The recommended replacement is asyncio
  from asyncore import write
  • 1
  • 2
  • 3

我先在cmd中输入下命令行,将python转成exe文件:

D:\>pyinstaller -F test.py --exclude-module _bootlocale
  • 1

输出如下,没有报任何ERROR或者WARNING

34 INFO: PyInstaller: 3.6
34 INFO: Python: 3.10.5
146 INFO: Platform: Windows-10-10.0.17763-SP0
147 INFO: wrote D:\test.spec
150 INFO: UPX is not available.
152 INFO: Extending PYTHONPATH with paths
['D:\\',
 'D:\\']
152 INFO: checking Analysis
152 INFO: Building Analysis because Analysis-00.toc is non existent
152 INFO: Initializing module dependency graph...
153 INFO: Caching module graph hooks...
157 INFO: Analyzing base_library.zip ...
2854 INFO: Processing pre-find module path hook   distutils
2854 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\yuyi\\AppData\\Local\\Programs\\Python\\Python310\\lib'
3481 INFO: Caching module dependency graph...
3597 INFO: running Analysis Analysis-00.toc
3600 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\Users\yuyi\AppData\Local\Programs\Python\Python310\python.exe
3762 INFO: Analyzing D:\test.py
3775 INFO: Processing module hooks...
3775 INFO: Loading module hook "hook-distutils.py"...
3776 INFO: Loading module hook "hook-encodings.py"...
4050 INFO: Loading module hook "hook-lib2to3.py"...
4052 INFO: Loading module hook "hook-pydoc.py"...
4052 INFO: Loading module hook "hook-sysconfig.py"...
4055 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
4055 INFO: Loading module hook "hook-xml.py"...
4080 INFO: Loading module hook "hook-_tkinter.py"...
4379 INFO: checking Tree
4379 INFO: Building Tree because Tree-00.toc is non existent
4382 INFO: Building Tree Tree-00.toc
4416 INFO: checking Tree
4417 INFO: Building Tree because Tree-01.toc is non existent
4418 INFO: Building Tree Tree-01.toc
4441 INFO: Looking for ctypes DLLs
4455 INFO: Analyzing run-time hooks ...
4457 INFO: Including run-time hook 'pyi_rth__tkinter.py'
4458 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
4464 INFO: Looking for dynamic libraries
4603 INFO: Looking for eggs
4603 INFO: Using Python library C:\Users\yuyi\AppData\Local\Programs\Python\Python310\python310.dll
4605 INFO: Found binding redirects:
[]
4610 INFO: Warnings written to D:\build\test\warn-test.txt
4642 INFO: Graph cross-reference written to D:\build\test\xref-test.html
4667 INFO: checking PYZ
4667 INFO: Building PYZ because PYZ-00.toc is non existent
4669 INFO: Building PYZ (ZlibArchive) D:\build\test\PYZ-00.pyz
5033 INFO: Building PYZ (ZlibArchive) D:\build\test\PYZ-00.pyz completed successfully.
5043 INFO: checking PKG
5043 INFO: Building PKG because PKG-00.toc is non existent
5044 INFO: Building PKG (CArchive) PKG-00.pkg
6825 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6844 INFO: Bootloader C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
6844 INFO: checking EXE
6844 INFO: Building EXE because EXE-00.toc is non existent
6845 INFO: Building EXE from EXE-00.toc
6846 INFO: Appending archive to EXE D:\dist\test.exe
6854 INFO: Building EXE from EXE-00.toc completed successfully.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

通过下命令行运行exe文件:

D:\dist>test.exe "D:\xxxx(某文件)" "xxxx(某文件)"
  • 1

运行后,会出现下方的错误:

[14172] mod is NULL - structSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[14172] mod is NULL - pyimod01_os_pathSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[14172] mod is NULL - pyimod02_archiveSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
[14172] mod is NULL - pyimod03_importersSystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\pyiboot01_bootstrap.py", line 17, in <module>
ModuleNotFoundError: No module named 'pyimod03_importers'
[14172] Failed to execute script pyiboot01_bootstrap
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

我找到了pyimod03_importers.py文件,用VSCode尝试编译,发现会出错

Traceback (most recent call last):
  File "C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\yuyi\.vscode\extensions\ms-python.python-2022.11.11891004\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
    cli.main()
  File "c:\Users\yuyi\.vscode\extensions\ms-python.python-2022.11.11891004\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 444, in main
    run()
  File "c:\Users\yuyi\.vscode\extensions\ms-python.python-2022.11.11891004\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 285, in run_file
    runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
  File "C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 289, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Users\yuyi\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\yuyi\AppData\Local\Programs\Python\Python310\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 29, in <module>
    SYS_PREFIX = sys._MEIPASS
AttributeError: module 'sys' has no attribute '_MEIPASS'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

目前还找不到相关问题的原因


2022年8月13日 新增

在家里的网络环境安装的pyinstaller,重新做了exe,该exe能用,执行命令行和返回代码如下:

D:\>pyinstaller -F text.py
137 INFO: PyInstaller: 4.10
137 INFO: Python: 3.6.3
138 INFO: Platform: Windows-10-10.0.22000-SP0
139 INFO: wrote D:\text.spec
143 INFO: UPX is not available.
146 INFO: Extending PYTHONPATH with paths
['D:\\']
331 INFO: checking Analysis
332 INFO: Building Analysis because Analysis-00.toc is non existent
332 INFO: Initializing module dependency graph...
334 INFO: Caching module graph hooks...
354 INFO: Analyzing base_library.zip ...
2990 INFO: Caching module dependency graph...
3176 INFO: running Analysis Analysis-00.toc
3182 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\dell\appdata\local\programs\python\python36-32\python.exe
3448 INFO: Analyzing D:\text.py
3471 INFO: Processing module hooks...
3472 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'...
3476 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'...
3563 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'...
3566 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'...
3569 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks'...
3839 INFO: Looking for ctypes DLLs
3841 INFO: Analyzing run-time hooks ...
3845 INFO: Including run-time hook 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py'
3849 INFO: Including run-time hook 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
3851 INFO: Including run-time hook 'c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
3857 INFO: Looking for dynamic libraries
3923 INFO: Looking for eggs
3923 INFO: Using Python library c:\users\dell\appdata\local\programs\python\python36-32\python36.dll
3926 INFO: Found binding redirects:
[]
3931 INFO: Warnings written to D:\build\text\warn-text.txt
3977 INFO: Graph cross-reference written to D:\build\text\xref-text.html
3991 INFO: checking PYZ
3991 INFO: Building PYZ because PYZ-00.toc is non existent
3992 INFO: Building PYZ (ZlibArchive) D:\build\text\PYZ-00.pyz
4445 INFO: Building PYZ (ZlibArchive) D:\build\text\PYZ-00.pyz completed successfully.
4456 INFO: checking PKG
4457 INFO: Building PKG because PKG-00.toc is non existent
4457 INFO: Building PKG (CArchive) text.pkg
5796 INFO: Building PKG (CArchive) text.pkg completed successfully.
5798 INFO: Bootloader c:\users\dell\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
5799 INFO: checking EXE
5800 INFO: Building EXE because EXE-00.toc is non existent
5800 INFO: Building EXE from EXE-00.toc
5801 INFO: Copying bootloader EXE to D:\dist\text.exe.notanexecutable
6587 INFO: Copying icon to EXE
6587 INFO: Copying icons from ['c:\\users\\dell\\appdata\\local\\programs\\python\\python36-32\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
6592 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
6593 INFO: Writing RT_ICON 1 resource with 3752 bytes
6593 INFO: Writing RT_ICON 2 resource with 2216 bytes
6593 INFO: Writing RT_ICON 3 resource with 1384 bytes
6594 INFO: Writing RT_ICON 4 resource with 37019 bytes
6594 INFO: Writing RT_ICON 5 resource with 9640 bytes
6594 INFO: Writing RT_ICON 6 resource with 4264 bytes
6594 INFO: Writing RT_ICON 7 resource with 1128 bytes
7037 INFO: Copying 0 resources to EXE
7038 INFO: Emedding manifest in EXE
7044 INFO: Updating manifest in D:\dist\text.exe.notanexecutable
7048 INFO: Updating resource type 24 name 1 language 0
7473 INFO: Appending PKG archive to EXE
14460 INFO: Building EXE from EXE-00.toc completed successfully.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

2022年8月16日新增

在网络上找到了相关的消息,pyinstaller只支持3.6~3.9的python版本,但如何更改并不清楚。

It sounds like the extension was not updated for python 3.10.
On 3.10 any module(s) that use the # variant when parsing arguments need to have a #define PY_SSIZE_T_CLEAN before including Python.h.
原文链接


已解决

目前站内大部分pyinstaller都不适用于3.10版本,我自己整理了目前最新的pyinstaller以及相关依赖包,不会出现以上问题。

放上我的资源 pyinstaller 5.3 所有依赖包,已经在3.10.5版本的python上测试过了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/367864
推荐阅读
相关标签
  

闽ICP备14008679号