[GH-ISSUE #46] Failed to execute script pyi_rth_win32comgenpy #44

Closed
opened 2026-02-26 12:20:17 +03:00 by kerem · 9 comments
Owner

Originally created by @nauticalcoder on GitHub (Feb 6, 2019).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/46

After creating an exe from my Python script, I am getting the following error when attempting to run the .exe.
Traceback (most recent call last): File "site-packages\PyInstaller\loader\rthooks\pyi_rth_win32comgenpy.py", line 47, in <module> File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module exec(bytecode, module.__dict__) File "site-packages\win32com\__init__.py", line 5, in <module> ImportError: No module named win32api [27000] Failed to execute script pyi_rth_win32comgenpy

Pywin32 was installed from the binary installed (after previously installing it from pip). I haven't found a workaround for this. The exe's were previously running but it kept throwing an error about a missing win32com module in the console window when auto-py-to-exe ran so I installed pywin32. Now I am getting the above error. Reverting the pywin32 installed does not have any effect.

Python 2.7

Originally created by @nauticalcoder on GitHub (Feb 6, 2019). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/46 After creating an exe from my Python script, I am getting the following error when attempting to run the .exe. `Traceback (most recent call last): File "site-packages\PyInstaller\loader\rthooks\pyi_rth_win32comgenpy.py", line 47, in <module> File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 395, in load_module exec(bytecode, module.__dict__) File "site-packages\win32com\__init__.py", line 5, in <module> ImportError: No module named win32api [27000] Failed to execute script pyi_rth_win32comgenpy` Pywin32 was installed from the binary installed (after previously installing it from pip). I haven't found a workaround for this. The exe's were previously running but it kept throwing an error about a missing win32com module in the console window when auto-py-to-exe ran so I installed pywin32. Now I am getting the above error. Reverting the pywin32 installed does not have any effect. Python 2.7
kerem closed this issue 2026-02-26 12:20:17 +03:00
Author
Owner

@brentvollebregt commented on GitHub (Feb 6, 2019):

Is this working before it is packaged? If so, then try adding win32api to the --hidden-import input field in the advanced tab

<!-- gh-comment-id:461125893 --> @brentvollebregt commented on GitHub (Feb 6, 2019): Is this working before it is packaged? If so, then try adding `win32api` to the --hidden-import input field in the advanced tab
Author
Owner

@nauticalcoder commented on GitHub (Mar 22, 2019):

I am not sure exactly what was going on with this but it is building now. I am not using any --hidden-import's. I did uninstall everything pywin32 related. The only pip installed that appears to be win32 related is pywin32-ctypes. I wish I had a better explanation for what fixed it.

<!-- gh-comment-id:475496346 --> @nauticalcoder commented on GitHub (Mar 22, 2019): I am not sure exactly what was going on with this but it is building now. I am not using any --hidden-import's. I did uninstall everything pywin32 related. The only pip installed that appears to be win32 related is `pywin32-ctypes`. I wish I had a better explanation for what fixed it.
Author
Owner

@brentvollebregt commented on GitHub (Mar 22, 2019):

win32api is part of the pywin32 package so it must have been getting added. This is handled by PyInstaller; unfortunately I cannot explain why it would have been added if you didn't use it.

<!-- gh-comment-id:475515821 --> @brentvollebregt commented on GitHub (Mar 22, 2019): win32api is part of the pywin32 package so it must have been getting added. This is handled by PyInstaller; unfortunately I cannot explain why it would have been added if you didn't use it.
Author
Owner

@bharathronanki commented on GitHub (Jan 6, 2020):

Is this working before it is packaged? If so, then try adding win32api to the --hidden-import input field in the advanced tab

I had the same problem in my exe file when converter from python code. But i didn't understand your answer '--hidden-import input field in the advance tab'. Can you please elaborate and help me solving my error.

<!-- gh-comment-id:571014644 --> @bharathronanki commented on GitHub (Jan 6, 2020): > Is this working before it is packaged? If so, then try adding `win32api` to the --hidden-import input field in the advanced tab I had the same problem in my exe file when converter from python code. But i didn't understand your answer '--hidden-import input field in the advance tab'. Can you please elaborate and help me solving my error.
Author
Owner

@brentvollebregt commented on GitHub (Jan 6, 2020):

The UI has an Advanced header. If you click on that, it will expand the body. There is an input by --hidden-import where you can put the import.

Please open a new issue if you are reporting an issue.

<!-- gh-comment-id:571022431 --> @brentvollebregt commented on GitHub (Jan 6, 2020): The UI has an `Advanced` header. If you click on that, it will expand the body. There is an input by `--hidden-import` where you can put the import. Please open a new issue if you are reporting an issue.
Author
Owner

@gabemorris12 commented on GitHub (Jan 6, 2021):

I had this same issue, but uninstalling and reinstalling didn't fix it for me. To fix this, I added the --hidden-import "pywin32" flag and it worked!

<!-- gh-comment-id:754979788 --> @gabemorris12 commented on GitHub (Jan 6, 2021): I had this same issue, but uninstalling and reinstalling didn't fix it for me. To fix this, I added the ```--hidden-import "pywin32"``` flag and it worked!
Author
Owner

@davidsam25 commented on GitHub (Apr 27, 2022):

I had the same issue, I've tried:

  • uninstall and reinstall everything which is pywin32, win32com related
  • Added on hidden-import pywin32, win32com, pypiwin32, pywintypes
  • Added in the path envs/xx/Lib/site-packages
  • Added also in Additional files
  • Even added a dll --add binary (saw in another forum) Lib/site-packages/pywin32_system32/pythoncom39.dll

Still not working! I don't know what to do! Any idea please?

Error :
ModuleNotFoundError: No module named 'win32api'
[49272] Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception!

<!-- gh-comment-id:1110841327 --> @davidsam25 commented on GitHub (Apr 27, 2022): I had the same issue, I've tried: - uninstall and reinstall everything which is pywin32, win32com related - Added on hidden-import pywin32, win32com, pypiwin32, pywintypes - Added in the path envs/xx/Lib/site-packages - Added also in Additional files - Even added a dll --add binary (saw in another forum) Lib/site-packages/pywin32_system32/pythoncom39.dll Still not working! I don't know what to do! Any idea please? Error : ModuleNotFoundError: No module named 'win32api' [49272] Failed to execute script 'pyi_rth_win32comgenpy' due to unhandled exception!
Author
Owner

@brentvollebregt commented on GitHub (Apr 29, 2022):

@davidsandbar are you sure the python installation / venv you are using to run auto-py-to-exe is the same installation / venv you have pywin32 etc installed in?

<!-- gh-comment-id:1112915797 --> @brentvollebregt commented on GitHub (Apr 29, 2022): @davidsandbar are you sure the python installation / venv you are using to run auto-py-to-exe is the same installation / venv you have pywin32 etc installed in?
Author
Owner

@davidsam25 commented on GitHub (Apr 29, 2022):

@davidsandbar are you sure the python installation / venv you are using to run auto-py-to-exe is the same installation / venv you have pywin32 etc installed in?

Many thanks for your help - at the end, what make it works was to open conda shell in admin mode, and run auto-py-to-exe from this window - and it worked

<!-- gh-comment-id:1112927236 --> @davidsam25 commented on GitHub (Apr 29, 2022): > @davidsandbar are you sure the python installation / venv you are using to run auto-py-to-exe is the same installation / venv you have pywin32 etc installed in? Many thanks for your help - at the end, what make it works was to open conda shell in admin mode, and run auto-py-to-exe from this window - and it worked
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#44
No description provided.