首页 > 编程问答 >TypeError:预期的字符串或类似字节的对象,在使用导入运行 Pyinstaller 时得到“NoneType”

TypeError:预期的字符串或类似字节的对象,在使用导入运行 Pyinstaller 时得到“NoneType”

时间:2024-07-23 05:04:47浏览次数:11  
标签:python pandas pyinstaller

我正在尝试从 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

相关文章

  • Python - 逆透视数据框
    我有一个按日期时间索引的表,每个日期时间都有多个层(中心和交货间隔):日期时间中心交货间隔结算点价格2024-01-0101:00:00休斯顿中心1......
  • 试图理解这个错误:致命的Python错误:PyEval_RestoreThread:该函数必须在持有GIL的情况下
    我有一个小型tkinter应用程序,我一直在其中实现最小的“拖放”,主要作为学习实验。我真正关心的是删除文件的文件路径。一切实际上都工作正常,直到我尝试在拖放后打包标签小部件。下面的最小工作示例。有问题的行会用注释指出。我通常不会在调试方面遇到太多麻烦,但我只是不知......
  • 如何使代码格式再次适用于 Python(Mac 上的 Visual Studio Code)?
    在Mac上,Option+Shift+F现在会显示“没有安装用于‘python’文件的格式化程序”。消息框:我尝试安装这个插件,但没有看到这种情况的变化:我已经为Python安装了这两个插件:但是正如@starball提到的,它可能已经减少了支持现在。......
  • 无法在 python 中安装 pip install expliot - bluepy 的 Building Wheel (pyproject.t
    在此处输入图像描述当我尝试在Windows计算机中通过cmd安装pipinstallexpliot包时,我收到2个错误名称×Buildingwheelforbluepy(pyproject.toml)didnotrunsuccessfully.│exitcode:1**AND**opt=self.warn_dash_deprecation......
  • python 用单斜杠-反斜杠替换url字符串中的双斜杠
    我的URL包含错误的双斜杠(“//”),我需要将其转换为单斜杠。不用说,我想保持“https:”后面的双斜杠不变。可以在字符串中进行此更改的最短Python代码是什么?我一直在尝试使用re.sub,带有冒号否定的正则表达式(即,[^:](//)),但它想要替换整个匹配项(包括前面......
  • 如何使用 Selenium Python 搜索 Excel 文件中的文本
    我有一些数据在Excel文件中。我想要转到Excel文件,然后搜索文本(取自网站表),然后获取该行的所有数据,这些数据将用于在浏览器中填充表格。示例:我希望selenium搜索ST0003然后获取名称,该学生ID的父亲姓名,以便我可以在大学网站中填写此信息。我想我会从网站......
  • Python 套接字请求在很多情况下都会失败
    我在python中尝试了超过5种不同的方法,尽管人们说它在其他论坛上有效,但所有这些方法都惨遭失败。importsocketmessage="test"clientsocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)clientsocket.connect(('1.1.1.1',80))clientsocket.send(mes......
  • Python 网络套接字
    我一直尝试通过Python访问该网站的websocket,但是需要绕过CloudFlare,现在我尝试通过cookie进行绕过,但是这不起作用。我已经尝试在没有cookie的情况下执行此操作,但这也不起作用。importwebsocketimportbase64importosdriver=selenium.webdriver.Firefox()driver.ge......
  • 如何在Python中使用Selenium提取data-v-xxx?
    因为我想查看每个class='num'内的文本是否大于0。如果测试通过,那么我需要获取venuen-name内的文本。我观察到,data-v是相同的。所以我的方法是获取相同的data-v-<hashvalue>来查找场地名称。我尝试了不同的方法来提取,但仍然无法提取。有什么建议吗?这是DOM<div......
  • Python:添加异常上下文
    假设我想提出一个异常并提供额外的处理信息;最好的做法是什么?我想出了以下方法,但对我来说有点可疑:definternal_function():raiseValueError("smellysocks!")defcontext_function():try:internal_function()exceptExceptionase:......