Getting TypeError when trying to convert a python file into an executable with pyinstaller

The intention is later on, to send questions via command lines to GPT4all and store the answer in a text document.
I wanted to convert the prevent code to an exe, but it produced an TypeError.

Here is the code so far:

from gpt4all import GPT4All

model = GPT4All("Meta-Llama-3-8B-Instruct.Q4_0.gguf", device='cpu')  # downloads / loads a 4.66GB LLM
with model.chat_session():
    with open("C:\Temp\Antwort.txt", "a") as a:
        print(model.generate("What is the capital of France?", max_tokens=1024), file=a)

That is the error:

(.venv) PS C:UserslbuntenbachPycharmProjectsGPT4all> pyinstaller --onefile Learning.py
1048 INFO: PyInstaller: 6.9.0, contrib hooks: 2024.7
1048 INFO: Python: 3.12.4
1115 INFO: Platform: Windows-10-10.0.19045-SP0
1115 INFO: Python environment: C:UserslbuntenbachPycharmProjectsGPT4all.venv
1131 INFO: wrote C:UserslbuntenbachPycharmProjectsGPT4allLearning.spec
1147 INFO: Module search paths (PYTHONPATH):
['C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Scripts\pyinstaller.exe',
 'C:\Users\lbuntenbach\AppData\Local\Programs\Python\Python312\python312.zip',
 'C:\Users\lbuntenbach\AppData\Local\Programs\Python\Python312\DLLs',
 'C:\Users\lbuntenbach\AppData\Local\Programs\Python\Python312\Lib',
 'C:\Users\lbuntenbach\AppData\Local\Programs\Python\Python312',
 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv',
 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages',
 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\setuptools\_vendor',
 'C:\Users\lbuntenbach\PycharmProjects\GPT4all']
2100 INFO: checking Analysis
2100 INFO: Building Analysis because Analysis-00.toc is non existent
2100 INFO: Running Analysis Analysis-00.toc
2100 INFO: Target bytecode optimization level: 0
2100 INFO: Initializing module dependency graph...
2119 INFO: Caching module graph hooks...
2190 INFO: Analyzing base_library.zip ...
7332 INFO: Loading module hook 'hook-encodings.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
9867 INFO: Loading module hook 'hook-heapq.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
12568 INFO: Loading module hook 'hook-pickle.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
16389 INFO: Caching module dependency graph...
16721 INFO: Looking for Python shared library...
16754 INFO: Using Python shared library: C:UserslbuntenbachAppDataLocalProgramsPythonPython312python312.dll
16754 INFO: Analyzing C:UserslbuntenbachPycharmProjectsGPT4allLearning.py
16918 INFO: Loading module hook 'hook-platform.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
19333 INFO: Loading module hook 'hook-charset_normalizer.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
19724 INFO: Loading module hook 'hook-certifi.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
20570 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
20768 INFO: Loading module hook 'hook-xml.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\Lib\site-packages\PyInstaller\hooks'...
21469 INFO: Loading module hook 'hook-importlib_resources.py' from 'C:\Users\lbuntenbach\PycharmProjects\GPT4all\.venv\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:UserslbuntenbachPycharmProjectsGPT4all.venvScriptspyinstaller.exe__main__.py", line 7, in <module>
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstaller__main__.py", line 231, in _console_script_run
    run()
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstaller__main__.py", line 215, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstaller__main__.py", line 70, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerbuildingbuild_main.py", line 1216, in main
    build(specfile, distpath, workpath, clean_build)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerbuildingbuild_main.py", line 1156, in build
    exec(code, spec_namespace)
  File "C:UserslbuntenbachPycharmProjectsGPT4allLearning.spec", line 4, in <module>
    a = Analysis(
        ^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerbuildingbuild_main.py", line 556, in __init__
    self.__postinit__()
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerbuildingdatastruct.py", line 184, in __postinit__
    self.assemble()
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerbuildingbuild_main.py", line 696, in assemble
    program_scripts.append(self.graph.add_script(script))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 268, in add_script
    self._top_script_node = super().add_script(pathname)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1160, in add_script
    self._process_imports(n)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 437, in _safe_import_hook
    ret_modules = super()._safe_import_hook(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2048, in _safe_import_hook
    target_modules = self.import_hook(
                     ^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1232, in import_hook
    target_package, target_module_partname = self._find_head_package(
                                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1411, in _find_head_package
    target_package = self._safe_import_module(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 501, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1792, in _safe_import_module
    self._process_imports(n)
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2591, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 368, in _safe_import_hook
    excluded_imports = self._find_all_excluded_imports(source_module.identifier)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependanalysis.py", line 356, in _find_all_excluded_imports
    excluded_imports.update(module_hook.excludedimports)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependimphook.py", line 316, in __getattr__
    self._load_hook_module()
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerdependimphook.py", line 383, in _load_hook_module
    self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallercompat.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:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerhookshook-importlib_resources.py", line 18, in <module>
    if check_requirement("importlib_resources < 1.2.0"):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagesPyInstallerutilshooks__init__.py", line 414, in check_requirement
    return parsed_requirement.specifier.contains(version, prereleases=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagespackagingspecifiers.py", line 906, in contains
    item = Version(item)
           ^^^^^^^^^^^^^
  File "C:UserslbuntenbachPycharmProjectsGPT4all.venvLibsite-packagespackagingversion.py", line 200, in __init__
    match = self._regex.search(version)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: expected string or bytes-like object, got 'NoneType'

So far it seems, that the return is None, but I can’t grasp, what ist producing the None value.
Could someone explain the origin of the None value and is there a way to fix this issue?
I’m new to Python and grateful for every piece of advice.

New contributor

lbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật