python win32com Causes Program crash - python

I wrote program to control iTunes by monitoring keystrokes from with pyHooks and then interfaceing with the iTunes COM interface.
The program works fine, the only problem I have is when I try to compile it with py2exe. The program always crashes with this traceback:
Traceback (most recent call last):
File "threading.pyc", line 527, in __bootstrap_inner
File "iTunesControl.py", line 24, in run
File "win32com\client\gencache.pyc", line 540, in EnsureDispatch
File "win32com\client\CLSIDToClass.pyc", line 46, in GetClass
KeyError: '{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}'
py2exe reports no errors...

The problem is probably that the py2exe version isn't able to access the cache of wrappers generated by win32com.
Here's a recipe for dealing with this problem.

Related

Making an executable python program with Snap7 for PLCs

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.

PyInstaller "You may load I/O plugins with the `skimage.io.use_plugin`"

useing Pyinstaller packages a python script
Pyinstaller version 3.2
OS:Ubuntu
Traceback (most recent call last):
File "<string>", line 57, in <module>
File "<string>", line 29, in feature_extract
File "caffe/io.py", line 295, in load_image
File "skimage/io/_io.py", line 100, in imread
File "skimage/io/manage_plugins.py", line 194, in call_plugin
RuntimeError: No suitable plugin registered for imread.
You may load I/O plugins with the `skimage.io.use_plugin` command. A list of all available plugins can be found using `skimage.io.plugins()`.
file_test returned -1
I have been getting above error. Could some one please tell me how would i fix it?
The problem seems to be related to this github issue, essentially the skimage.io._plugins submodule is making life hard for Pyinstaller.
To make sure everything you need is packaged you should have a hook file that contains
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
datas = collect_data_files("skimage.io._plugins")
hiddenimports = collect_submodules('skimage.io._plugins')
(or if you already have a hook file with these, extend the current datas and hiddenimports).

Python Error while building code using waf

I had code that worked fine. I shut down my PC (Ubuntu) and then, built the same software (ns-3) and now I get the error:
Traceback (most recent call last):
File "./waf", line 148, in <module>
Scripting.prepare(t, cwd, VERSION, wafdir)
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Scripting.py", line 102, in prepare
prepare_impl(t,cwd,ver,wafdir)
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Scripting.py", line 95, in prepare_impl
main()
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Scripting.py", line 130, in main
fun(ctx)
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Scripting.py", line 269, in build
bld=check_configured(bld)
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Scripting.py", line 219, in check_configured
bld.load_dirs(proj[SRCDIR],proj[BLDDIR])
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Build.py", line 245, in load_dirs
self.load()
File "/home/ns-allinone-3.6/ns-3.6/.waf-1.5.8-12763e767c863088b8579dbeeb8265b6/wafadmin/Build.py", line 78, in load
if f:data=cPickle.load(f)
EOFError
I am just amazed at this, how could 2 minutes before everything was fine and now I am screwed by this error.
What should I do, I am totally bewildered. I have a deadline and suddenly this code stops, it worked fine, only change I did was to switch off my PC.
NS-3.6 is a very very old ns-3 release which you are trying to build with a new system (gcc compiler, python etc). I think the only solution to solve the problem is to update the simulator to a new release.
Try to rebuild it. First write: rm -rf build and build from scratch

pyinstaller and win32com

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.

Trouble running an application made with PyInstaller, importing GTK--searching nonexistent directories

I am trying to create an executable of my Python application that uses PyGTK to make a GUI. I have a well-established, automated build process using Pyinstaller that has worked for me for a previous application. Suffice it to say that it calls the usual Makespec.py and Build.py with 32-bit Python 2.7, with Pyinstaller configured for 32 bits. The resulting 32-bit application works fine on my machine and another machine running Windows 7 64-bit, but fails on 32-bit Windows XP with this error:
C:\OutNav_0_64\OutNav_0.64>outnav
Traceback (most recent call last):
File "<string>", line 23, in <module>
File "C:\Pyinstaller-1.5\iu.py", line 436, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 521, in doimport
File "C:\Users\462974\Documents\Local Sandbox\tools\utilities\Oni\build\pyi.win32\OutNav\outPYZ1.pyz/gtk", line 40, in
<module>
File "C:\Pyinstaller-1.5\iu.py", line 477, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 495, in doimport
File "C:\Pyinstaller-1.5\iu.py", line 297, in getmod
File "C:\Pyinstaller-1.5\archive.py", line 468, in getmod
File "C:\Pyinstaller-1.5\iu.py", line 109, in getmod
ImportError: DLL load failed: The specified procedure could not be found.
The strange part is, there is no C:\Pyinstaller-1.5 directory on my machine or the one experiencing the error. I have no idea why it is attempting to run code from this nonexistent directory, or what the missing DLL is. Can anyone help me fold PyGTK into my application?
NOTE: The first line of the trace, line 23 in my program, is
import gtk
UPDATE: My manager successfully ran it on 64-bit Windows XP.
UPDATE 2: He was mistaken, it was 64-bit Windows 7. It has the same problem on his Windows XP installation.
Also, on the original machine it failed on, from the directory of the executable, I did this:
>>> import imp
>>> fp = open('gtk._gtk.pyd', 'rb')
>>> mod = imp.load_module('gtk._gtk', fp, 'gtk._gtk.pyd', ('.pyd', 'rb', 3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
As far as I can tell, the .pyd file (which is in the format of a .DLL file) generated by pyinstaller on Windows 7 is incompatible with Windows XP. My solution was to simply recreate my build process on a Windows XP machine, which solved it to my satisfaction.

Categories

Resources