1

after trying running exe built by pyinstaller I've recived that message:

Traceback (most recent call last):
  File "Lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_win32comgenpy.py", line 40, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "win32com\__init__.py", line 6, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "pythoncom.py", line 4, in <module>
  File "pywintypes.py", line 44, in __import_pywin32_system_module__
ImportError: Module 'pythoncom' isn't in frozen sys.path ['C:\\Users\\KONRAD~1.DZI\\AppData\\Local\\Temp\\_MEI23842\\base_library.zip', 'C:\\Users\\KONRAD~1.DZI\\AppData\\Local\\Temp\\_MEI23842\\lib-dynload', 'C:\\Users\\KONRAD~1.DZI\\AppData\\Local\\Temp\\_MEI23842']
[11136] Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception!

I've tried to built exe file with hidden-import of win32com module and without and that won't work anyways. Also I've reinstall win32com but that also don't helped.

pyinstaller --onefile --hidden-import win32com main.py

After removing import win32com.client and removing this part:

if mail.lower() == 'tak':
   outlook = win32.Dispatch('outlook.application')
   mail = outlook.CreateItem(0)

   mail.To = dane['email']

   mail.Subject = dane['temat']

   if dane['zawartość'].lower() == 'brak':
      mail.Body = ''

   else:
      mail.Body = dane['zawartość']
   email_cc = ""
   cc_list = dane['cc']
   if cc_list[0].lower() == "brak":
      pass
   else:
      for email in dane['cc']:
         email_cc = email_cc + email + ';'

   for file in os.listdir(rozdzielone_pliki + '\\'):
      file_location = rozdzielone_pliki + '\\' + file
      mail.Attachments.Add(file_location)

   mail.Send()#

Everything works fine.

What should I do? Thanks for help.

Konrad
  • 21
  • 1
  • 4
  • does this help? https://stackoverflow.com/questions/17891071/importerror-with-cx-freeze-and-pywin32-module-pythoncom-isnt-in-frozen-sys-p – manaclan Nov 26 '21 at 09:35
  • Solution in this post isn't change anything in my case :( – Konrad Nov 26 '21 at 10:31

1 Answers1

-1

I have same problem, and just append pythoncomxx.dll path to pyinstaller *.spec file. like this(of course, you can use --collect-binaries parameter in commandline):

main.spec

a = Analysis(['main.py'],
             pathex = [],
             binaries = [('your\\python\\path\\Library\\bin\\pythoncom*.dll','.')]
             ...
             )

then, re-run:

pyinstaller main.spec

and it's work.

This work for me.

Providing a possible solution is not a guarantee that it will work.

uitb
  • 11
  • 2