pyInstaller having trouble bundling a package containing SWIG modules - python

I’m running into an issue getting pyInstaller to bundle a module that contains SWIG modules. I have followed each of the guidelines listed in the pyInstaller doc which details SWIG support.
I get the following error when running the exe:
# sphinxbase._ad_win32 not found in PYZ
Traceback (most recent call last):
File "StartListening.py", line 10, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\__init__.py", line 35, in <module>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "c:\users\allen\appdata\local\programs\python\python36-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\sphinxbase\ad_win32.py", line 32, in <module>
File "site-packages\sphinxbase\ad_win32.py", line 31, in swig_import_helper
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sphinxbase._ad_win32'
However, sphinxbase._ad_win32 does exists as a pyd file. I’m running Windows 10; why is pyInstaller having trouble bundling this module?
The third-party package I’m ultimately trying to import is SpeechRecognition which depends on pocketsphinx which depends on sphinxbase which is the module that is having issues.
Here is the object reference returned by
importlib.import_module('sphinxbase._ad_win32')
in the SWIG-generated python wrapper if that is helpful to someone:
<module 'sphinxbase._ad_win32' from 'C:\\Users\\bob\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages\\sphinxbase\\_ad_win32.pyd'>
Python version: 3.6.5
Edit: After some more research, I tried adding the .pyd to the 'binaries' list in the .spec file as well as adding 'sphinxbase._ad_win32' to the 'hidden-imports' list and combinations there-between, but this did not work either. The binary is there, in the correct location, I can't figure out why the bundled app can't find it.

Related

pyinstaller's exe fails to run

So I have been working on a battleship game project in pygame and wanted to start recording game results to help with building an AI. Unfortunately when I go through with this command for pyinstaller:
pyinstaller -D -w -n Battleship -F Gui.py
It goes through and creates the exe with no issue, when I go to launch the exe it throws this error seen in the picture below.
Following that path in the error it seems to be when I call my database script then when I try and import pymongo. If I exclude the database side of my script when I make the exe it runs just find and of course is just missing the database interaction portion.
I am running this through pycharm and it works just fine in this development setting but again when I go to create an exe through pyinstaller it results in the error.
Edit 1: So I have run this now without the -w in cmd window and recieved the following:
C:\Users\14402\SynologyDrive\BattleShip\dist>Battleship.exe
Traceback (most recent call last):
File "Gui.py", line 3, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "DataBase.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\__init__.py", line 102, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\collection.py", line 38, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\common.py", line 42, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "pymongo\compression_support.py", line 18, in <module>
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 493, in exec_module
File "snappy\__init__.py", line 20, in <module>
File "snappy\__init__.py", line 11, in _delvewheel_init_patch_0_0_9
File "os.py", line 1111, in add_dll_directory
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\14402\\AppData\\Local\\Temp\\_MEI1811162\\python_snappy.libs'
[152752] Failed to execute script 'Gui' due to unhandled exception!
Along with this I have checked to see if python-snappy is installed and it is:
PS C:\Users\14402\SynologyDrive\BattleShip> pip install python-snappy
Requirement already satisfied: python-snappy in c:\users\14402\synologydrive\battleship\venv\lib\site-packages (0.6.1)
WARNING: Error parsing requirements for pytz: [Errno 2] No such file or directory: 'c:\\users\\14402\\synologydrive\\battleship\\venv\\lib\\site-packages\\pytz-2022.2.1.dist-info\\METADATA'
Finally I will be going through tomorrow and seeing if I can make a simplified version to see if I can better pinpoint, but from my testing this gets thrown when the exe is starting and hits the import for pymongo.
So after Alexander said they were able to open things and run it no problem. I created a new project and pulled over all the code and reimported the libraries and it ran just fine. I must have something hanging over in my previous project in my library that is causing the problem but it is resolved now! Thank you all for your questions and help, first time posting and it was a bit rough.

ModuleNotFoundError: No module named 'sklearn.neighbors._partition_nodes' with PyInstaller

I have been trying to build a Windows executable from Python files using PyInstaller (and auto-py-to-exe, but the problem really resides with PyInstaller). Once the executable is built (using --onedir) , I try to launch it and it crashes with this error message:
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "sklearn\feature_selection\__init__.py", line 28, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "sklearn\feature_selection\_mutual_info.py", line 9, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
File "sklearn\neighbors\__init__.py", line 6, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 1050, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "sklearn\neighbors\_ball_tree.pyx", line 1, in init sklearn.neighbors._ball_tree
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sklearn.neighbors._partition_nodes'
[17176] Failed to execute script 'Make_Model' due to unhandled exception!
I have tried to add sklearn.neighbors._partition_nodes to the hidden imports list, but I still obtain the same error message. I have looked at the very helpful auto-py-to-exe page and the not-as-helpful PyInstaller page, but nothing specific to my problem can be found.
I know that scikit-learn is notoriously difficult to deal with when it comes to PyInstaller, but can anybody provide some guidance about this problem?
In case someone asks, the code is written in Python 3.7.11 in a Windows 10 environment.
I managed to resolve this by doing what sometimes is the best solution: I deleted all my previous attempts at building the executable and re-started afresh using solely auto-py-to-exe. This time, adding sklearn.neighbors._partition_nodes to the hidden import list worked. I was then able to move on to the next problem (XGBoost), but there are plenty of answers available for that.

PySide2 with Pyinstaller: Failed to execute script pyi_rth_pkgres

so I have been using Pyinstaller the last couple of months to package and distribute my applications as single exe files, however I recently made the switch from using Tkinter in my GUI apps to using PySide2 (QT5 Wrapper). The thing is, I'm not able to package those executables, as I'm getting the following error at runtime:
Exception: [Errno 2] No such file or directory: 'C:\\support\\signature\\loader.py'
Traceback (most recent call last):
File "pyscript", line 23, in bootstrap
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\support\\signature\\loader.py'
AttributeError: module 'signature_loader' has no attribute 'pyside_type_init'
SystemError: could not initialize part 2
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 11, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "pkg_resources\__init__.py", line 33, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "platform.py", line 116, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "subprocess.py", line 50, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "C:\Users\felip\AppData\Roaming\Python\Python37\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "signal.py", line 45, in <module>
File "c:\program files\python37\lib\functools.py", line 54, in update_wrapper
value = getattr(wrapped, attr)
SystemError: <method-wrapper '__get__' of getset_descriptor object at 0x0000023A7ACE88B8> returned a result with an error set
[9240] Failed to execute script pyi_rth_pkgres
The package should consist of one .py file, one .uic QT file and a SQLite3 .db .
I have tried packaging with Pyinstaller in several ways, however the same exception arises when trying to execute the application.
I'm using Python 3.7.2, Pyinstaller 3.4, PySide 5.12.1 and peewee 3.9.2 .
Any help is greatly appreciated.
The following worked for me:
1. uninstalled pyinstaller and installed the developer version from git (but didn't change anything so far - maybe that's not necessary)
2. typed pyinstaller -v example.pyw
3. used the returned value from 2 as hidden import. In my case pyinstaller --hidden-import=4.0.dev0+869062597f example.pyw

exe created from py2exe returns: "AttributeError: 'module' object has no attribute 'CUIAutomation'"

Its a simple GUI Script written with tinkter module of python. and Putty tool is called to make some SSH connections. Issue seems to be with compatibilty.
python version : 3.4
pywinauto version : 0.6.2
py2exe version : 0.9.2.2
the created exe file are opening in some windows 7 PCs and throw some error in others. All PCs are Windows 7.
traceback from the cmd;
C:\tools\easy_Login\easy_Login>easy_login.exe
Traceback (most recent call last):
File "easy_login.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pywinauto\__init__.py", line 40, in <modul
e>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pywinauto\findwindows.py", line 42, in <mo
dule>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pywinauto\controls\__init__.py", line 36,
in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pywinauto\controls\uiawrapper.py", line 44
, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pywinauto\uia_defines.py", line 175, in <module>
File "C:\Python34\lib\site-packages\pywinauto\uia_defines.py", line 163, in _build_pattern_ids_dic
File "C:\Python34\lib\site-packages\pywinauto\uia_defines.py", line 50, in __call__
File "C:\Python34\lib\site-packages\pywinauto\uia_defines.py", line 63, in __init__
AttributeError: 'module' object has no attribute 'CUIAutomation'
C:\tools\easy_Login\easy_Login>
Try renaming your your source python script "login.py" rather than "easy_login.py" then re-run py2exe to create "login.exe"
It sounds odd, but I had the exact same issue with some W7 machines throwing that error when I was running "ateme_installer.exe" (generated with pyinstaller) and after ruling out all other issues, eventually found that when I renamed it "installer.py" and suddenly the output "installer.exe" worked everywhere!

AttributeError in Py2exe

I made my py file executable using py2exe. My setup.py is as follows:
from distutils.core import setup
import py2exe
setup(windows=['main.py'])
When I tried to run main.exe, I get an error and was referred to main.log which reads:
Traceback (most recent call last):
File "main.py", line 20, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "C:\Python34\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\tslib.pyx", line 2839, in init pandas.tslib (pandas\tslib.c:79846)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\algos.pyx", line 64, in init pandas.algos (pandas\algos.c:179610)
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "<loader>", line 10, in <module>
File "<loader>", line 6, in __load
File "pandas\lib.pyx", line 1, in init pandas.lib (pandas\lib.c:77889)
AttributeError: 'module' object has no attribute '__pyx_capi__'
It looks like line 20 in my main.py file (import pandas as pd) triggered the problem. This type of error is referenced in a pull request here and they suggested adding a blank __init__.py file. I did so and got same result. I found a well commented post here (not directly dealing with py2exe) that suggests this might be due to mutual top-level imports or circular dependencies. This problem seems well known and has been mentioned at least twice on Stackoverflow in the past year (e.gs: here and here) but no clear solution has been given.
Perhaps we can get more clarity now with your feedback.
Python 3.4.2; py2exe 0.9.2.0
Was running into the same issue with pandas, but I got it working after updating to the most recent version.
It seems this error was recently addressed, and was resolved in Pandas 15.2
https://github.com/pydata/pandas/issues/8602
I was running in the same errors with Python 3.4.4.
My solution was to fix the import statement in C:\Pythob34\lib\site-packagespythoncom.py.
Original:
import pywintypes
pywintypes.import_pywin32_system_module("pythoncom", globals())
Changed To:
from pywintypes import import_pywin32_system_module
import_pywin32_system_module("pythoncom", globals())

Categories

Resources