Bootstrap

QGIS使用pyinstaller时找不到pyconfig.h

测试脚本

import numpy as np


arr = np.array([1, 2, 3])

print(arr)

打包命令

"C:\Program Files\QGIS 3.10\bin\python-qgis-ltr.bat" -m PyInstaller -c test.py

错误详情

58 INFO: PyInstaller: 4.1
59 INFO: Python: 3.7.0
60 INFO: Platform: Windows-10-10.0.19041-SP0
64 INFO: wrote D:\workspace\test_numpy\test.spec
66 INFO: UPX is not available.
72 INFO: Extending PYTHONPATH with paths
['D:\\workspace\\test_numpy', 'D:\\workspace\\test_numpy']
177 INFO: checking Analysis
177 INFO: Building Analysis because Analysis-00.toc is non existent
178 INFO: Initializing module dependency graph...
184 INFO: Caching module graph hooks...
203 INFO: Analyzing base_library.zip ...
4018 INFO: Caching module dependency graph...
4095 INFO: running Analysis Analysis-00.toc
4098 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by C:\PROGRA~1\QGIS3~1.10\apps\Python37\python.exe
4151 INFO: Analyzing D:\workspace\test_numpy\test.py
4580 INFO: Processing pre-find module path hook distutils from 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4581 INFO: distutils: retargeting to non-venv dir 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib'
5911 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
6371 INFO: Processing pre-find module path hook site from 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
6371 INFO: site: retargeting to fake-dir 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\fake-modules'
9024 INFO: Processing module hooks...
9025 INFO: Loading module hook 'hook-difflib.py' from 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\hooks'...
9031 INFO: Excluding import of doctest from module difflib
9031 INFO: Loading module hook 'hook-distutils.py' from 'C:\\PROGRA~1\\QGIS3~1.10\\apps\\Python37\\lib\\site-packages\\PyInstaller\\hooks'...
Unable to find "C:\PROGRA~1\QGIS3~1.10\apps\Python37\Include\pyconfig.h" when adding binary and data files.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)

错误分析

初步分析是缺少pyconfig.h导致,进入C:\Program Files\QGIS 3.10\apps\Python37\include果然发现只有sip.h一个文件,最后搜索电脑上哪里有pyconfig.h,最后在C:\Program Files\Python37\include中发现存在pyconfig.h,拷贝至C:\Program Files\QGIS 3.10\apps\Python37\include重新打包即可

;