我正在尝试从 Python 创建可执行文件,但收到以下错误。我创建了一个干净的环境,并尝试仅通过导入和文件中的简单
print('Hello World')
来重现该问题,如下所示:
import tkinter as tk
import threading
from tkinter import filedialog
from tkcalendar import DateEntry
from datetime import datetime
import sys
import pandas as pd
import sqlite3
from pathlib import Path
import os
import warnings
from my_functions import launch_tableau_reader
from prime_read_data import prime_read_data
from prime_main_analysis import prime_main_analysis
print('Hello World')
当我删除时:
from tkcalendar import DateEntry
import pandas as pd
from my_functions import launch_tableau_reader
from prime_read_data import prime_read_data
from prime_main_analysis import prime_main_analysis
Pyinstaller 设法运行而没有任何问题。以下是当我尝试使用所有导入运行 Pyinstaller 时收到的错误
166 INFO: PyInstaller: 6.9.0, contrib hooks: 2024.7
167 INFO: Python: 3.12.4
189 INFO: Platform: Windows-10-10.0.19045-SP0
189 INFO: Python environment: C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312
191 INFO: wrote C:\Users\guy.lamdan\OneDrive - Playtika Ltd\new_prime\test_exe.spec
192 INFO: Module search paths (PYTHONPATH):
['C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Scripts\\pyinstaller.exe',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\python312.zip',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\DLLs',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages',
'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\setuptools\\_vendor',
'C:\\Users\\guy.lamdan\\OneDrive - Playtika Ltd\\new_prime']
414 INFO: checking Analysis
416 INFO: Building because C:\Users\guy.lamdan\OneDrive - Playtika Ltd\new_prime\test_exe.py changed
416 INFO: Running Analysis Analysis-00.toc
416 INFO: Target bytecode optimization level: 0
416 INFO: Initializing module dependency graph...
417 INFO: Caching module graph hooks...
425 INFO: Analyzing base_library.zip ...
1271 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
1646 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
2158 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
2812 INFO: Caching module dependency graph...
2878 INFO: Looking for Python shared library...
2881 INFO: Using Python shared library: C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\python312.dll
2881 INFO: Analyzing C:\Users\guy.lamdan\OneDrive - Playtika Ltd\new_prime\test_exe.py
2949 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\tkcalendar\calendar_.py:221: SyntaxWarning: invalid escape sequence '\ '
font = kw.pop("font", "Liberation\ Sans 9")
3029 INFO: Loading module hook 'hook-babel.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
3284 INFO: Loading module hook 'hook-pytz.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
3481 INFO: Loading module hook 'hook-pkg_resources.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4119 INFO: Loading module hook 'hook-platform.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4138 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4150 INFO: Loading module hook 'hook-packaging.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4173 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
4208 INFO: Loading module hook 'hook-jaraco.text.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
4298 INFO: Loading module hook 'hook-importlib_resources.py' from 'C:\\Users\\guy.lamdan\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 231, in _console_script_run
run()
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 215, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\__main__.py", line 70, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 1216, in main
build(specfile, distpath, workpath, clean_build)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 1156, in build
exec(code, spec_namespace)
File "C:\Users\guy.lamdan\OneDrive - Playtika Ltd\new_prime\test_exe.spec", line 4, in <module>
a = Analysis(
^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 556, in __init__
self.__postinit__()
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
self.assemble()
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\building\build_main.py", line 696, in assemble
program_scripts.append(self.graph.add_script(script))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 268, in add_script
self._top_script_node = super().add_script(pathname)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1160, in add_script
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
target_package, target_module_partname = self._find_head_package(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
target_package = self._safe_import_module(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1245, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1245, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1245, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
target_package, target_module_partname = self._find_head_package(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
target_package = self._safe_import_module(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
target_package, target_module_partname = self._find_head_package(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
target_package = self._safe_import_module(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1245, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 437, in _safe_import_hook
ret_modules = super()._safe_import_hook(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2048, in _safe_import_hook
target_modules = self.import_hook(
^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1232, in import_hook
target_package, target_module_partname = self._find_head_package(
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in _find_head_package
target_package = self._safe_import_module(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 501, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1792, in _safe_import_module
self._process_imports(n)
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2591, in _process_imports
target_modules = self._safe_import_hook(*import_info, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 368, in _safe_import_hook
excluded_imports = self._find_all_excluded_imports(source_module.identifier)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\analysis.py", line 356, in _find_all_excluded_imports
excluded_imports.update(module_hook.excludedimports)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\imphook.py", line 316, in __getattr__
self._load_hook_module()
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\depend\imphook.py", line 383, in _load_hook_module
self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\compat.py", line 583, in importlib_load_source
mod_loader.exec_module(mod)
File "<frozen importlib._bootstrap_external>", line 995, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\hooks\hook-importlib_resources.py", line 18, in <module>
if check_requirement("importlib_resources < 1.2.0"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 414, in check_requirement
return parsed_requirement.specifier.contains(version, prereleases=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\packaging\specifiers.py", line 914, in contains
item = Version(item)
^^^^^^^^^^^^^
File "C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\packaging\version.py", line 198, in __init__
match = self._regex.search(version)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'
我试图使用 Pyinstaller 从 Python 创建可执行文件。
这个错误信息 "TypeError: expected string or bytes-like object, got 'NoneType'" 说明 PyInstaller 在处理你的代码时遇到了一个问题,它期望一个字符串或字节类型的对象,但却得到了一个 NoneType 对象。
根据你的描述和错误日志,问题可能出在以下几个方面:
1.
importlib_resources
版本冲突:
-
错误日志显示
check_requirement("importlib_resources < 1.2.0")
这一行代码出现了问题。 -
这意味着你的代码或者依赖库可能需要
importlib_resources
1.2.0 之前的版本,但你安装的版本更高。 -
解决方法:
尝试安装旧版本的
importlib_resources
,例如:bash pip install 'importlib_resources<1.2.0'
2.
tkcalendar
的
font
参数问题:
-
错误日志中出现了
C:\Users\guy.lamdan\AppData\Local\Programs\Python\Python312\Lib\site-packages\tkcalendar\calendar_.py:221: SyntaxWarning: invalid escape sequence '\ '
的警告信息。 -
这表明
tkcalendar
库中可能存在错误的转义字符,导致 PyInstaller 无法正确解析。 -
解决方法:
-
尝试升级
tkcalendar
到最新版本,看是否修复了该问题。 -
如果升级后问题仍然存在,可以尝试手动修改
tkcalendar\calendar_.py
文件,将font = kw.pop("font", "Liberation\ Sans 9")
中的\
替换为//
或直接使用原始字符串r"Liberation\ Sans 9"
。
-
尝试升级
3. 其他依赖库问题:
- 虽然你已经尝试了干净的环境,但仍然有可能存在其他依赖库的问题导致了这个错误。
-
解决方法:
-
逐个排查你导入的库,特别是
pandas
、sqlite3
、自定义的my_functions
、prime_read_data
和prime_main_analysis
等,看是否存在版本冲突或其他问题。 -
可以尝试使用
pip install -U <package_name>
来升级这些库到最新版本。
-
逐个排查你导入的库,特别是
4. PyInstaller 版本问题:
- 虽然几率较小,但也可能你使用的 PyInstaller 版本过旧,导致无法正确处理你的代码。
-
解决方法:
尝试升级 PyInstaller 到最新版本:
bash pip install --upgrade pyinstaller
调试建议:
- 可以尝试在代码中添加一些打印语句,查看程序执行到哪一步出现了问题,以及相关变量的值是什么。
-
可以在 PyInstaller 的命令中添加
--debug all
选项,生成更详细的日志信息,帮助你定位问题。
如果以上方法都无法解决问题,请提供更详细的错误信息,包括完整的错误日志以及你的代码结构,以便我更好地帮助你分析问题。
标签:python,pandas,pyinstaller From: 78778654