I searched for how can I produce a installer for my Python project. I found a good alternative, that is the py2exe module. This is used on a setup.py.
But my project uses a com server with win32com module into the OpenOPC module. For this reason, after I produce a standalone directorie with the exe file, this executable does not works, returning this exception:
IOError: [Errno 2] No such file or directory:
'C:\\Users\\(project directory)\\dist\\lib\\shared.zip\\win32com\\gen_py\\__init__.py'
I searched more about this and found this page: http://www.py2exe.org/index.cgi/Py2exeAndWin32com
This page teaches a 'model' for setup.py to include a com server as module. But I did not understand this 'model'. It is generic for all com servers and do not introduce where should I include the OpenOPC module. I have tried some ways to use this model like:
from distutils.core import setup
import py2exe
import sys
class Target:
def __init__(self):
self.version = version
self.company_name = author
self.copyright = license_
self.name = name
self.description = description
self.modules = ['C:\\OpenOPC\\src\\OpenOPC.py']
self.create_exe = True
self.create_dll = False
sys.argv.append('py2exe')
setup(name=name,
version=version,
author=author,
author_email=author_email,
maintainer=maintainer,
maintainer_email=maintainer_email,
url=url,
license=license_,
description=description,
long_description=long_description,
keywords=keywords,
platforms=platforms,
console=console, zipfile=zipfile,
com_server=[Target()])
Unfortunately this did not work. I tried to put some others files or directories on modules into Target class constructor. It seems that I have to put the OpenOPC module here if it is not in other point.
I did:
sys.argv.append('py2exe')
setup(name=name,
version=version,
author=author,
author_email=author_email,
maintainer=maintainer,
maintainer_email=maintainer_email,
url=url,
license=license_,
description=description,
long_description=long_description,
keywords=keywords,
platforms=platforms,
console=console, zipfile=zipfile,
options=options)
where
options = {'py2exe': {'packages': ['win32com']}}
That is it. Worked. And my application have a OPC client and not OPC server. If it would had a OPC server (COM server), maybe it would have been even more difficult.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.