Найти - Пользователи
Полная версия: Сборка Python-проекта pyinstaller-ом. После старта exe-файла выдаёт ошибку об отсутствии модуля
Начало » Python для новичков » Сборка Python-проекта pyinstaller-ом. После старта exe-файла выдаёт ошибку об отсутствии модуля
1 2
Dva2lin
Собираю проект из нескольких питон-скриптов. IKS_pro.py - стартовый скрипт, с него весь проект “начинается”. Используется tkinter в качестве GUI. Так же подгружаются некоторые дополнительные модули (tkcalendar). Pyinstaller нормально собирает exe-файл; командная строка:
 pyinstaller  --clean -n "IKS pro" -d imports -w -i "IKS_pro.ico" IKS_pro.py

После старта exe-файла выдаётся сообщение об ошибке:

 Traceback (most recent call last):
  File "IKS_pro.py", line 516, in <module>
  File "IKS_pro.py", line 66, in __init__
  File "IKS_pro.py", line 200, in init_menu
  File "tkcalendar\dateentry.py", line 128, in __init__
  File "tkcalendar\calendar_.py", line 259, in __init__
  File "babel\dates.py", line 285, in get_day_names
  File "babel\core.py", line 773, in days
  File "babel\core.py", line 439, in _data
  File "babel\localedata.py", line 137, in load
  File "babel\localedata.py", line 143, in load
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1140, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'babel.numbers'
файлик numbers.py в соответствующей папке site-packages\babel присутствует. Поскольку первый раз “собираю” exe-файл то просто не знаю за что зацепиться. Прошу помочь советом.
ZerG
Попробуй так если читать не хочешь
https://github.com/brentvollebregt/auto-py-to-exe
Dva2lin
Попытался использовать для сборки auto-py-to-exe.
программа сформировала вот такую командную строку:
 pyinstaller --noconfirm --onedir --windowed --icon "C:/zDistributives/IKSpro-dist/IKS_pro.ico" --name "IKS pro" --hidden-import "babel" --add-data "C:/Python/Python311/Lib/site-packages/babel/numbers.py;."  "C:/zDistributives/IKSpro-dist/IKS_pro.py"

Упаковка в EXE не произошла. Лог получился такой (отличается от предыдущего поста):
привожу здесь “нижнюю часть” лога
 942383 INFO: checking EXE
942386 INFO: Building EXE because EXE-02.toc is non existent
942399 INFO: Building EXE from EXE-02.toc
942414 INFO: Copying bootloader EXE to C:\Users\vg\AppData\Local\Temp\tmph9gi_q56\build\IKS pro\IKS pro.exe
942500 INFO: Copying icon to EXE
An error occurred while packaging
Traceback (most recent call last):
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 33, in pywin32error
    yield
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\pywin32\win32api.py", line 209, in BeginUpdateResource
    return _resource._BeginUpdateResource(filename, delete)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\core\cffi\_resource.py", line 114, in _BeginUpdateResource
    result = check_null(
             ^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\core\cffi\_util.py", line 78, in __call__
    self._raise_error(function_name)
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\core\cffi\_util.py", line 89, in _raise_error
    raise exception
OSError: [WinError 225] Operation did not complete successfully because the file contains a virus or potentially unwanted software
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Python\Python311\Lib\site-packages\auto_py_to_exe\packaging.py", line 132, in package
    run_pyinstaller()
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 198, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\__main__.py", line 69, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 1071, in main
    build(specfile, distpath, workpath, clean_build)
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\build_main.py", line 1011, in build
    exec(code, spec_namespace)
  File "C:\Users\vg\AppData\Local\Temp\tmph9gi_q56\IKS pro.spec", line 18, in <module>
    exe = EXE(
          ^^^^
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\api.py", line 628, in __init__
    self.__postinit__()
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\datastruct.py", line 184, in __postinit__
    self.assemble()
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\api.py", line 741, in assemble
    self._retry_operation(icon.CopyIcons, build_name, self.icon)
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\building\api.py", line 1003, in _retry_operation
    return func(*args)
           ^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\utils\win32\icon.py", line 209, in CopyIcons
    return CopyIcons_FromIco(dstpath, [srcpath])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\PyInstaller\utils\win32\icon.py", line 143, in CopyIcons_FromIco
    hdst = win32api.BeginUpdateResource(dstpath, 0)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\pywin32\win32api.py", line 208, in BeginUpdateResource
    with _pywin32error():
  File "C:\Python\Python311\Lib\contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "C:\Python\Python311\Lib\site-packages\win32ctypes\pywin32\pywintypes.py", line 37, in pywin32error
    raise error(exception.winerror, exception.function, exception.strerror)
win32ctypes.pywin32.pywintypes.error: (225, '', 'Operation did not complete successfully because the file contains a virus or potentially unwanted software')
Project output will not be moved to output folder
Complete.

Из антивирусов на компе только встроеный в винду. Папка с Питонов внесена в исключения для антивируса.
ZerG
Попробуй виндовый дефендер остановить на время
Dva2lin
Временно отключил windows defender.
Сборка EXE произошла. Но сразу после старта EXE появилось сообщение
об ошибке

 Traceback (most recent call last):
  File "decimal.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 676, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 573, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1233, in create_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\zDistributives\IKSpro-dist\output\IKS pro\_internal\numbers.py", line 28, in <module>
    from babel.core import Locale, default_locale, get_global
ImportError: cannot import name 'Locale' from partially initialized module 'babel.core' (most likely due to a circular import) (C:\zDistributives\IKSpro-dist\output\IKS pro\_internal\babel\core.pyc)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "IKS_pro.py", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "tkcalendar\__init__.py", line 26, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "tkcalendar\dateentry.py", line 35, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "tkcalendar\calendar_.py", line 35, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "babel\__init__.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "babel\core.py", line 19, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "babel\plural.py", line 12, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "decimal.py", line 8, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "_pydecimal.py", line 157, in <module>
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\zDistributives\IKSpro-dist\output\IKS pro\_internal\numbers.py", line 28, in <module>
    from babel.core import Locale, default_locale, get_global
ImportError: cannot import name 'Locale' from partially initialized module 'babel.core' (most likely due to a circular import) (C:\zDistributives\IKSpro-dist\output\IKS pro\_internal\babel\core.pyc)

Насколько я понял модуль babel отвечает за мультиязычнность Питона.
Все показанные ошибки так или иначе связаны с этим модулем.
Может их появления быть связано с тем, что у меня на компе установлена Балтийская кодировка
в качестве основной?


ZerG
pip install –upgrade babel

https://gregoryszorc.com/docs/pyoxidizer/main/pyoxidizer_managing_projects.html

Dva2lin
ZerG
pip install –upgrade

Сделано ещё вчера!
Ссылку на PyOxidizer изучаю…
Dva2lin
Всё ))) Кажется справился.
Необходимо было модуль babel в командной строке pyinstaller-a
добавлять и в –hidden-import и в –collect-submodules одновременно.

В результате командная строка выглядела вот так:
 pyinstaller --noconfirm --onedir --windowed --icon "IKS_pro.ico" --name "IKS pro" --hidden-import "babel" --collect-submodules "babel"  "IKS_pro.py"

ZerG, спасибо за помощь и наводки !


ZerG
Я бы в сторону PyOxidizer смотрел
Сколько помню pyinstaller с ним пожизненно какието проблемы
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB