徐高翔的个人网站

windows平台下开发PyQt5工具埋坑记

2018-12-29

软硬件环境

  • Windows 10 64bit
  • anaconda3 with python 3.6.4
  • pyinstaller
  • pyqt5

前言

最近在做一个运行于windows平台的基于PyQt5的图形化工具,本文记录期间碰到的问题及一些python小知识点,希望对您有用。

ui文件转化成py文件

windows下,我们使用pyuic5.bat这个脚本来生成

1
D:\tools\python3.5.1\Lib\site-packages\PyQt5\pyuic5.bat designer\mainwindow.ui -o gui\ui_mainwindow.py

pyinstaller出现ModuleNotFoundError: No module named 'setuptools._vendor'

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
$ pyinstaller -F --noconsole --clean --distpath release main.py -n KeyHacker
1256 INFO: PyInstaller: 3.4
1256 INFO: Python: 3.6.4
1256 INFO: Platform: Windows-10-10.0.17134-SP0
1259 INFO: wrote D:\longjing\L7660_KeyHacker\KeyHacker.spec
1264 INFO: UPX is not available.
1264 INFO: Removing temporary files and cleaning cache in C:\Users\djstava\AppData\ Roaming\pyinstaller
1269 INFO: Extending PYTHONPATH with paths
['D:\\longjing\\L7660_KeyHacker', 'D:\\longjing\\L7660_KeyHacker']
1269 INFO: checking Analysis
1269 INFO: Building Analysis because Analysis-00.toc is non existent
1269 INFO: Initializing module dependency graph...
1276 INFO: Initializing module graph hooks...
1312 INFO: Analyzing base_library.zip ...
12882 INFO: running Analysis Analysis-00.toc
12940 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of fin al executable
required by d:\tools\anaconda3\python.exe
14660 INFO: Caching module hooks...
14667 INFO: Analyzing D:\longjing\L7660_KeyHacker\main.py
19144 INFO: Processing pre-find module path hook distutils
22631 INFO: Processing pre-find module path hook site
22649 INFO: site: retargeting to fake-dir 'd:\\tools\\anaconda3\\lib\\site-packages \\PyInstaller\\fake-modules'
26019 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'setuptools._vendor'
Traceback (most recent call last):
File "d:\tools\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\tools\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\tools\anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 17, in <module>
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
self.__postinit__()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 443, in assemble
priority_scripts.append(self.graph.run_script(script))
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 201, in run_script
self._top_script_node = super(PyiModuleGraph, self).run_script(pathname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1348, in run_script
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1422, in import_hook
target_module = self._load_tail(target_package, target_module_partname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1635, in _load_tail
submodule = self._safe_import_module(head, mname, submodule)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2417, in _safe_import_hook
edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1438, in import_hook
target_module, target_attr_names):
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1726, in _import_importable_package_submodules
attr_name, submodule_name, package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2417, in _safe_import_hook
edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1438, in import_hook
target_module, target_attr_names):
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1726, in _import_importable_package_submodules
attr_name, submodule_name, package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1422, in import_hook
target_module = self._load_tail(target_package, target_module_partname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1635, in _load_tail
submodule = self._safe_import_module(head, mname, submodule)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2417, in _safe_import_hook
edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1438, in import_hook
target_module, target_attr_names):
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1726, in _import_importable_package_submodules
attr_name, submodule_name, package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1422, in import_hook
target_module = self._load_tail(target_package, target_module_partname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1635, in _load_tail
submodule = self._safe_import_module(head, mname, submodule)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2417, in _safe_import_hook
edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1438, in import_hook
target_module, target_attr_names):
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1726, in _import_importable_package_submodules
attr_name, submodule_name, package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1421, in import_hook
source_package, target_module_partname, level)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1573, in _find_head_package
target_module_headname, target_package_name, source_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2028, in _load_module
m = self._load_package(fqname, pathname, packagepath)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2813, in _load_package
self._load_module(fqname, fp, buf, stuff)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1422, in import_hook
target_module = self._load_tail(target_package, target_module_partname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1635, in _load_tail
submodule = self._safe_import_module(head, mname, submodule)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 271, in _safe_import_module
module_basename, module_name, parent_package)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1990, in _safe_import_module
module_name, file_handle, pathname, metadata)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2082, in _load_module
self._scan_code(m, co, co_ast)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2544, in _scan_code
self._process_imports(module)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2743, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2221, in _safe_import_hook
target_attr_names=None, level=level, edge_attr=edge_attr)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1422, in import_hook
target_module = self._load_tail(target_package, target_module_partname)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1635, in _load_tail
submodule = self._safe_import_module(head, mname, submodule)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 260, in _safe_import_module
hook_module.pre_safe_import_module(hook_api)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-setuptools.extern.six.moves.py", line 34, in pre_safe_import_module
for real_module_name, six_module_name in real_to_six_module_name.items():
AttributeError: 'str' object has no attribute 'items'

解决方法

1
python -m pip install -U pip setuptools

pyinstaller打包pyqt5出现Cannot find existing PyQt5 plugin directories

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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$ pyinstaller -F --noconsole --clean --distpath release main.py -n KeyHacker
1128 INFO: PyInstaller: 3.4
1128 INFO: Python: 3.6.4
1128 INFO: Platform: Windows-10-10.0.17134-SP0
1131 INFO: wrote D:\longjing\L7660_KeyHacker\KeyHacker.spec
1136 INFO: UPX is not available.
1136 INFO: Removing temporary files and cleaning cache in C:\Users\djstava\AppData\Roaming\pyinstaller
1141 INFO: Extending PYTHONPATH with paths
['D:\\longjing\\L7660_KeyHacker', 'D:\\longjing\\L7660_KeyHacker']
1141 INFO: checking Analysis
1141 INFO: Building Analysis because Analysis-00.toc is non existent
1141 INFO: Initializing module dependency graph...
1150 INFO: Initializing module graph hooks...
1193 INFO: Analyzing base_library.zip ...
12826 INFO: running Analysis Analysis-00.toc
12889 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\tools\anaconda3\python.exe
14617 INFO: Caching module hooks...
14624 INFO: Analyzing D:\longjing\L7660_KeyHacker\main.py
19452 INFO: Processing pre-find module path hook distutils
19979 INFO: Processing pre-find module path hook site
19995 INFO: site: retargeting to fake-dir 'd:\\tools\\anaconda3\\lib\\site-packages\\PyInstaller\\fake-modules'
25781 INFO: Processing pre-safe import module hook setuptools.extern.six.moves
42967 INFO: Processing pre-safe import module hook win32com
53994 INFO: Processing pre-safe import module hook six.moves
57020 INFO: Loading module hooks...
57020 INFO: Loading module hook "hook-babel.py"...
57442 INFO: Loading module hook "hook-Crypto.py"...
Traceback (most recent call last):
File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'Crypto.Math'
57621 INFO: Loading module hook "hook-cryptography.py"...
59154 INFO: Loading module hook "hook-distutils.py"...
59191 INFO: Loading module hook "hook-encodings.py"...
59361 INFO: Loading module hook "hook-lib2to3.py"...
59373 INFO: Loading module hook "hook-pkg_resources.py"...
61394 INFO: Loading module hook "hook-pycparser.py"...
61821 INFO: Loading module hook "hook-pydoc.py"...
61828 INFO: Loading module hook "hook-PyQt5.py"...
62041 WARNING: Hidden import "PyQt5.sip" not found!
62041 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
62370 WARNING: Unable to find Qt5 translations C:/Users/builder/mc3/conda-bld/qt_1505945264697/_h_env/Library/translations\qtbase_*.qm. These translations were not packaged.
62370 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
Traceback (most recent call last):
File "d:\tools\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "d:\tools\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\tools\anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
exec(text, spec_namespace)
File "<string>", line 17, in <module>
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
self.__postinit__()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
module_hook.post_graph()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
self._load_hook_module()
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 823, in load_module
File "<frozen importlib._bootstrap_external>", line 682, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 684, in _load
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in <module>
hiddenimports, binaries, datas = add_qt5_dependencies(__file__)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 514, in add_qt5_dependencies
more_binaries = qt_plugins_binaries(plugin, namespace=namespace)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 132, in qt_plugins_binaries
pdir = qt_plugins_dir(namespace=namespace)
File "d:\tools\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 117, in qt_plugins_dir
""".format(namespace, ", ".join(paths)))
Exception:
Cannot find existing PyQt5 plugin directories
Paths checked: C:/Users/builder/mc3/conda-bld/qt_1505945264697/_h_env/Library/plugins

解决方法

1
2
pip install pyqt5
pyinstaller --paths D:\tools\anaconda3\Lib\site-packages\PyQt5\Qt\bin -F --noconsole --clean --distpath release main.py -n KeyHacker

判断大小端

1
2
3
import sys

print(sys.byteorder)

16进制字串转为10进制数字

1
print(int('ff', 16))

10进制数转化成16进制字符串

1
2
# type(hex(255))是str
print(hex(255))

byte和str的相互转换

字符串按位补0

1
2
3
4
5
6
7
8
9
n = "123"
s = n.zfill(5)
print(s)
# 00123

n = 123
s = "%05d" % n
print(s)
# 00123

16进制中的字母大小写转换

Python提供了ordchr两个内置的函数,用于字符与ASCII码之间的转换

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

def UCaseChar(ch):
# a ~ z
if ord(ch) in range(97, 122):
return chr(ord(ch) - 32)
return ch

def LCaseChar(ch):
# A ~ Z
if ord(ch) in range(65, 91):
return chr(ord(ch) + 32)
return ch

def UCase(str):
return ''.join(map(UCaseChar, str))

def LCase(str):
return ''.join(map(LCaseChar, str))

print(LCase('ABC123abc'))
print(UCase('ABC123abc'))

# 输出
# abc123abc
# ABC123ABC

工具推荐

windows全局搜索工具, listary,体积小,速度快,五星推荐

本文链接 https://xugaoxiang.com/2018/12/29/windows平台下开发PyQt5工具埋坑记/

推荐文章(由hexo文章推荐插件驱动)

使用支付宝打赏
使用微信打赏

请博主喝咖啡!