Comments (8)
Yes, it works perfectly before packing it. And in that case, win32com saves the server in:
C:\Users\emaimone\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\win32com\server
In parallel, I noticed that in the distutils_buildexe.py module there are a lot of commented lines, including this method:
##def build_comserver(self, target, template, arcname, boot_script="com_servers"):
## # Build a dll and an exe executable hosting all the com
## # objects listed in module_names.
that apparently does what I need.
I will try to uncomment this and other related methods in this module and see what I get.
That may take some time though...
from py2exe.
Thank you for reporting this, but I am afraid I cannot help you. I know nothing about win32com servers.
Do you have a way to know if the python process runs for real or if it crashes? If it crashes, the traceback could be very useful. If it does not crash, then it might also be that the issue is not in py2exe...
from py2exe.
Thank you for your prompt response
The Python process runs OK, no crashes, no error messages. From PythonWin Trace Collector:
Registering COM Server
Requesting elevation and retrying...
Registering COM Server
Registered: PythonZ.COMTest (for debugging)
Redirecting output to win32trace remote collector
The problem is that the generated COM server is not pointing to the code inside the distribution folder (as it did when I use py2exe for Python 2.7)
In the old py2exe, setup.up would look like:
setup(name="name",
com_server=["COMbuilder"],
options={"py2exe": options})
In this version of py2exe com_server does not produce an exe file (nor a dll, btw).
To replace "com_server" with "console + ctypes_com_server" as I did, is the right way to do it?
I understand that there is no full compatibility with the setup-scripts for Python 2, but there might be a way to replicate the build-out of functional win32com servers, right? Or this is something that is not necessarily in the roadmap?
Many thanks
from py2exe.
You can try the old script from Python 2, if you want. After a brief look in the codebase, it seems that the com_server
keyword is still accepted.
Unfortunately, I am not one of the original authors of py2exe
, hence there are a lot of features that I have never heard about, not to mention used. com_servers
and ctypes_com_server
are two of them, so I have no idea if those should work on Python 3 or not. I guess the fastest way for you would be to try.
About the roadmap, honestly I do not have any. I am trying to maintain the core of py2exe
functional, adapt it to new Python versions when they are released, and fix the issues that I can. I thought once or twice to review the available features and drop some of them (since I am not able to maintain everything alone), and probably com_server
would have been put in the to-be-dropped list.
Nevertheless, it's not dropped yet and all the code is still there, so this leaves to you a chance to test it (including with old scripts) and, potentially, to fix the issues that might arise. I can provide you limited support, but unless you can find more information (some log/debug printouts, e.g. the path that the server is trying to access), I do not see a way to help you at the moment.
from py2exe.
Fair enough. I will do some more research, post my findings and eventually try to fix the issue (although I am afraid that it can be beyond my scarce knowledge of the depths of Python and win32 :-) )
For now, what I found is the path that the server is trying to access is library.zip\win32com\server
py2exe-27 (with com_server=[module] in setup.py) generated the following files into that folder:
dispatcher.pyc
exception.pyc
factory.pyc
localserver.pyc
policy.pyc
register.pyc
util.pyc
__init__.pyc
while py2exe-37 (with ctypes_com_server = [module] in setup.py) generates only
register.pyc
__init__.pyc
Does that ring any bell?
Tks
from py2exe.
Not really, I am sorry, I do not know this feature at all. Do you have a way to test if your COM server works without packing it with py2exe
? This is usually what I do when I analyze an issue, but it seems that this feature also generates a lot of code, so I am not sure this is possible in this case.
from py2exe.
After spending a ton of man hours on this, I made a few findings:
- it was not necessary to uncomment any piece of code. The functionality necessary to register a com server is refactored in other modules of py2exe
- Changing my setup. py to:
from distutils.core import setup
import py2exe
py2exe_options = dict(
packages = ["comtypes.server"],
optimize=0,
compressed=False,
bundle_files=3,
dist_dir='distc08',
)
setup(name="name",
ctypes_com_server=[{ "modules": "COMbuilder",},],
options={"py2exe": py2exe_options},
)
after >python setup.py py2exe
, I tried to register the COM with >REGSVR32 COMbuilder.dll
- Then I got a persistent error msg popping up:
File "comtypes\client\_code_cache.pyc", line 156, in _get_module_filename
OSError: [WinError 126] The specified module could not be found.
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'DllRegisterServer' is not defined
- I found a very old post in stackoverflow saying that:
There's a bug in py2exe on 64 bit Python. The sys.frozendllhandle, initialized by py2exe, is invalid such that win32api.GetModuleFileName(sys.frozendllhandle) fails.
You might want to try the patched py2exe installers at http://www.lfd.uci.edu/~gohlke/pythonlibs/#py2exe
- After some (a lot) more investigation, I changed the way py2exe was getting the DLL file name in
COMTYPES.client._code_cache.py
, from:
path = _get_module_filename(sys.frozendllhandle)
to:
import win32api
path = win32api.GetModuleFileName(sys.frozendllhandle)
to avoid the GetModuleFindName function built into py2exe
- That cleared the error messages and I got a nice:
BUT that was not true. The COM Server does not get registered.
- So, I decided to give up. Please close the issue, but do not drop the com_server feature from py2exe yet.
It is a powerful feature and it would be nice to have it in Python 3.
Hopefully, someone else can solve the puzzle and make it work.
Thank you
from py2exe.
Closing the issue as no progress has been made. Feel free to reopen it if you have more info.
from py2exe.
Related Issues (20)
- Link on the py2exe wiki page does not go anywhere HOT 2
- Missing LICENSE in wheels HOT 4
- AssertionError with Python embeddable package HOT 1
- Py_OptimizeFlag not set correctly during Python initialization
- OSError: [WinError 87] The parameter is incorrect. HOT 2
- PYTHONPATH module location HOT 1
- Exe is created by doesn't run (opens then closes)
- Simple pygame example tries to lookup files inside of `library.zip` HOT 1
- Support Python 3.12 HOT 23
- Impossible to specify different version info for each of the binaries with the new freeze API. HOT 3
- pynput import break the file HOT 1
- PYTHONIOENCODING is ignored
- pendulum package doesn't initialize when unpacking from zipfile
- add version for python 3.12 too
- usage missing
- Does py2exe support 'QtWebEngineWidgets' of PySide6?
- How do I get an app using jaydebapi to work as an executable ?
- Failure to import zipextimporter with error "No module named '_memimporter'"
- [freeze][zipfile] Dependent packages and modules are not zipped to library.zip or packed to .exe bin
- ImportError: MemoryLoadLibrary failed loading PyQt5\QtWidgets.pyd: The specified module could not be found. (126)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py2exe.