So I'm confused about how to get pyinstaller to build an application that uses win32com. I have a script that runs with no problem from IDLE or command line that interacts with excel via
xl = Dispatch('Excel.Application')
followed by some other really basic excel calls, then closes. I've seen advice to include "clsctx=pythoncom.CLSCTX_LOCAL_SERVER" as an argument to Dispatch, but it doesn't change anything. Whenever I build the script, I get an error similar to this
Traceback (most recent call last):
File "<string>", line 7, in <module>
File "C:\Python27\trunk\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python27\trunk\iu.py", line 521, in doimport
exec co in mod.__dict__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client", line 11,
in <module>
File "C:\Python27\trunk\iu.py", line 436, in importHook
mod = _self_doimport(nm, ctx, fqname)
File "C:\Python27\trunk\iu.py", line 521, in doimport
exec co in mod.__dict__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 662, in <module>
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 58, in __init__
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 649, in Rebuild
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 65, in _SaveDicts
File "Myskript\build\pyi.win32\Myskript\outPYZ1.pyz/win32com.client.gencache",
line 141, in GetGeneratePath
IOError: [Errno 22] invalid mode ('w') or filename: 'C:\\Python27\\trunk\\Myskri
pt\\dist\\Myskript.exe?844863\\__init__.py'
That's copied from this german question http://www.python-forum.de/viewtopic.php?f=1&t=25010 but my error is basically the same. I tried to implement the advice given on that page to no avail either.
I know next to nothing about COM stuff, just hoping to get this little excel app to run.
EDIT: Also tried importing pythoncom and running "CoInitialize()" (based on this guy Call MS Access module function from Python after compiling with py2exe fails saying that his script ran fine with pyinstaller) but that didn't change anything either. Really at a loss here and appreciate any advice.
I'm not sure if you are still using py2exe, i was about to try your workaround when i stumbled into this thread:
Call MS Access module function from Python after compiling with py2exe fails
The "solution" was using Pyinstaller that has a bunch of workarounds implemented on by default depending on your script. I tried it with my pywin32 script that uses excel and word com objects and it worked perfectly without any tweaks.
Related
I am having an issue with a program, which uses panda3d. It works perfectly when executed as a pythonscript, but the version, which is compiled (or rather packaged) by PyInstaller throws the exception below.
:display(warning): Unable to load libpandagl.so: No error.
Known pipe types:
(all display modules loaded.)
Traceback (most recent call last):
File "Shipsim3d_1-1.py", line 930, in <module>
File "Shipsim3d_1-1.py", line 23, in __init__
File "direct/showbase/ShowBase.py", line 339, in __init__
File "direct/showbase/ShowBase.py", line 1024, in openDefaultWindow
File "direct/showbase/ShowBase.py", line 1059, in openMainWindow
File "direct/showbase/ShowBase.py", line 769, in openWindow
File "direct/showbase/ShowBase.py", line 749, in <lambda>
File "direct/showbase/ShowBase.py", line 821, in _doOpenWindow
File "direct/showbase/ShowBase.py", line 650, in makeDefaultPipe
File "direct/directnotify/Notifier.py", line 130, in error
Exception: No graphics pipe is available!
Your Config.prc file must name at least one valid panda display
library via load-display or aux-display.
[5466] Failed to execute script 'Shipsim3d_1-1' due to unhandled exception!
Usually, there is a Config.prc file in the etc subdirectory of the panda3d site-package directory. This file is non-existent in the packaged version. But if I create this subdirectory there, and copy the files to it as well, it still doesn't work and it still throws the same exception. There is a line "loadPrcData("win-size 1080 1920")" in my main program as well. Could this be part of the problem in any way? Or is there something else i am missing?
Thanks in advance
I solved this problem by including the whole panda3d lib:
pyinstaller --add-data="path/to/panda3d;panda3d" -wF main.py
I have written different Python projects using PyQT5 and now trying to create their .exe files to make them standalone and executable but whenever I try using pyinstaller command:
pyinstaller --onefile myfile.py
the created .exe file always crashes. But in my other system, when create .exe files using the same pyinstaller command, the .exe files run well. So why am I having issues creating .exe files in this particular system? What could be wrong please? My files contains python classes of different widgets and the scripts run well in the editors, the GUIs open well when run from the editor but not as a standalone. Now I want them as standalone. I have also used auto-py-to-exe, same issue. How do I resolve this?
I am also attaching a screenshot of the pyinstaller details of both systems to this post. The two descriptions (details) are captured in the photo, the one on the larger screen is the one of the system I am having issues with, while the smaller display is the one of the system where the .exe files are created and runs successfully without any issue. I noticed in the one running successfully, the attributes are more compared to the one having an issue. The one without an issue has [recursive-copy meta data],[splash image file], [disable windowed traceback], [--target -architecture arch], [-codesign identity IDENTITY], [--osx-entitlements-filename-FILENAME] whereas the pyinstaller having issues in my other system does not have it.
The below is some of the errors I get.
Traceback (most recent call last):
File "f:\installed program files\python\python 39\lib\site.py", line 169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "f:\installed program files\python\python 39\lib\importlib\util.py", line 2, in <module>
from . import abc
File "f:\installed program files\python\python 39\lib\importlib\abc.py", line 17, in <module>
from typing import Protocol, runtime_checkable
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1359, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
Remainder of file ignored
Error processing line 1 of f:\installed program files\python\python
39\lib\site-packages\zope.event-4.5.0-py3.6-nspkg.pth:
Traceback (most recent call last):
File "f:\installed program files\python\python 39\lib\site.py", line
169, in addpackage
exec(line)
File "<string>", line 1, in <module>
File "f:\installed program files\python\python 39\lib\importlib\util.py", line 2, in <module>
from . import abc
File "f:\installed program files\python\python 39\lib\importlib\abc.py",
line 17, in <module>
from typing import Protocol, runtime_checkable
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1359, in <module>
class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
File "f:\installed program files\python\python 39\lib\site-packages\typing.py", line 1007, in __new__
self._abc_registry = extra._abc_registry
AttributeError: type object 'Callable' has no attribute '_abc_registry'
I have found a solution to it and hope others having similar issue who come across this post will use the suggestion too. I had to pip uninstall typing. i.e
pip uninstall typing
This helps fix whatever issue there was and my .exe files run well using pyinstaller without crashing. After uninstalling typing module, run the pyinstaller command again to create your executables.
I'm having a similar issue on Python 3.8.7, and I can't find the solution.
In my project, I'm using pydub.AudioSegment to get audio from a file and then exporting that audio in a different format. My code works perfectly when I'm running the python file directly. However, when I convert it to an executable with pyinstaller, run the program and get to the point of importing the audio with pydub, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 269, in <module>
File "main.py", line 213, in convertfile
File "main.py", line 133, in cloud_upload
File "pydub\audio_segment.py", line 728, in from_file
File "pydub\utils.py", line 274, in mediainfo_json
File "subprocess.py", line 804, in __init__
File "subprocess.py", line 1142, in _get_handles
OSError: [WinError 6] The handle is invalid
pydub call in my program looks like this:
sound = AudioSegment.from_file(filepath)
sound.export(new_filepath, format="ogg",codec='libopus')
I've tried to add stdin=subprocess.DEVNULL and stdin=subprocess.PIPE in utils.py on line 274, but that didn't work either. Maybe I added them incorrectly, though, so suggestions like that are also highly appreciated.
I've managed to solve the problem only by removing --onefile option from pyinstaller and dropping ffmpeg.exe and ffprobe.exe into the resulted folder with the main.exe file.
That's not a good solution to the problem as I'd still prefer to use --onefile; but it works.
I'm still open to suggestions on how to make it work with --onefile or just generally why this is hapenning.
Chances are is that PyInstaller cannot recognize the imported plugin. Although if you are trying to make a app, I suggest using a shortcut instead, it is better due to the fact that you can customize the icon for the shortcut. It is what many apps mainly use.
I've been trying to make a program in python using Snap7, but now I want it to make an executable of it. I used py2exe to make the *.exe file and run it on Windows without python installed. However, everytime I try to open the application, the cmd window show me this error.
Traceback (most recent call last):
File "Sniffer.py", line 22, in <module>
File "snap7\client.pyc", line 34, in __init__
File "snap7\common.pyc", line 54, in load_library
File "snap7\common.pyc", line 47, in __init__
File "ctypes\__init__.pyc", line 440, in LoadLibrary
File "ctypes\__init__.pyc", line 362, in __init__
WindowsError: [Error 193] %1 is not a valid Win32 application
What should I do?
There was a problem with the *.dll files that comes with the SNAP7 library. I replaced the files with the 32-bit version of it and it works now.
Questions with similar issue:
Parallel Python - too many files and Python too many open files (subprocesses)
I am using Parallel Python [V1.6.2] to run tasks. The task processes an input file and outputs a log/report. Say, there are 10 folders each with 5000 ~ 20000 files which are read in parallel, processed and logs written out. Each file is approx 50KB ~ 250KB
After ~6 Hours of running, Parallel Python fails with the following error.
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 342, in __init__
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 506, in set_ncpus
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 140, in __init__
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 146, in start
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
File "/usr/lib/python2.7/subprocess.py", line 1135, in _execute_child
File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec
OSError: [Errno 24] Too many open files
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 66, in apport_excepthook
ImportError: No module named fileutils
Original exception was:
Traceback (most recent call last):
File "PARALLEL_TEST.py", line 746, in <module>
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 342, in __init__
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 506, in set_ncpus
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 140, in __init__
File "/usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py", line 146, in start
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
File "/usr/lib/python2.7/subprocess.py", line 1135, in _execute_child
File "/usr/lib/python2.7/subprocess.py", line 1091, in pipe_cloexec
OSError: [Errno 24] Too many open files
While I understand, this could be the issue in subprocess pointed out here http://bugs.python.org/issue2320, but, seems the solution is only part of Py V3.2. I am currently tied to Py V2.7.
I would like to know if the following suggestion helps:
[1]http://www.parallelpython.com/component/option,com_smf/Itemid,1/topic,313.0
*) Adding worker.t.close() in destroy() method of /usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/pp.py
*) Increasing BROADCAST_INTERVAL in /usr/local/lib/python2.7/dist-packages/pp-1.6.2-py2.7.egg/ppauto.py
I would like to know if there is a fix available/Work Around for this issue in Python V2.7.
Thanks in Advance
My team recently stumbled upon a similar issue with the same file handle resource exhaustion issue while running celeryd task queue jobs. I believe the OP has nailed it and it's most likely the messy code in suprocess.py lib in Python 2.7 and Python 3.1.
As suggested in , Python Bug#2320, please pass in close_fds=True everywhere you call subprocess.Popen(). In fact they make that a default in Python 3.2 while also fixing the underlying race condition issue. See more details in that ticket.
I had left at some lines to destroy the job servers. job_server.destroy() fixes the issue.