Giter Site home page Giter Site logo

COM server not working about py2exe HOT 8 CLOSED

py2exe avatar py2exe commented on May 24, 2024
COM server not working

from py2exe.

Comments (8)

emaimone avatar emaimone commented on May 24, 2024 1

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.

albertosottile avatar albertosottile commented on May 24, 2024

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.

emaimone avatar emaimone commented on May 24, 2024

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.

albertosottile avatar albertosottile commented on May 24, 2024

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.

emaimone avatar emaimone commented on May 24, 2024

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.

albertosottile avatar albertosottile commented on May 24, 2024

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.

emaimone avatar emaimone commented on May 24, 2024

After spending a ton of man hours on this, I made a few findings:

  1. 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
  2. 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

  1. 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
  1. 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

https://stackoverflow.com/questions/4619701/python-64-bit-dll-com-server-registration-problem-on-64-bit-windows-7

  1. 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

  1. That cleared the error messages and I got a nice:

image

BUT that was not true. The COM Server does not get registered.

  1. 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.

albertosottile avatar albertosottile commented on May 24, 2024

Closing the issue as no progress has been made. Feel free to reopen it if you have more info.

from py2exe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.