### 软硬件环境 * Windows 10 64bit * anaconda3 with python 3.6.4 * pyinstaller * pyqt5 ### 前言 最近在做一个运行于`windows`平台的基于`PyQt5`的图形化工具,本文记录期间碰到的问题及一些`python`小知识点,希望对您有用。 ### ui文件转化成py文件 在`windows`下,我们使用`pyuic5.bat`这个脚本来生成 ```bash pyuic5.bat designer/mainwindow.ui -o gui/ui_mainwindow.py ``` ### pyinstaller出现`ModuleNotFoundError: No module named 'setuptools._vendor'` ```bash $ 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' ``` 解决方法 ```bash python -m pip install -U pip setuptools ``` ### pyinstaller打包pyqt5出现`Cannot find existing PyQt5 plugin directories` ```bash $ 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 ``` 解决方法 ```bash pip install pyqt5 pyinstaller --paths D:\tools\anaconda3\Lib\site-packages\PyQt5\Qt\bin -F --noconsole --clean --distpath release main.py -n KeyHacker ``` ### 判断大小端 ```python import sys print(sys.byteorder) ``` ### 16进制字串转为10进制数字 ```python print(int('ff', 16)) ``` ### 10进制数转化成16进制字符串 ```python # type(hex(255))是str print(hex(255)) ``` ### byte和str的相互转换 ![](https://code.xugaoxiang.com/xugaoxiang/blog/raw/master/images/python/str_byte.jpg) ### 字符串按位补0 ```python n = "123" s = n.zfill(5) print(s) # 00123 n = 123 s = "%05d" % n print(s) # 00123 ``` ### 16进制中的字母大小写转换 Python提供了`ord`和`chr`两个内置的函数,用于字符与`ASCII`码之间的转换 ```python 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`,体积小,速度快,五星推荐


Comments

comments powered by Disqus