We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2023-08-31 04:28 PM
Dear Community,
I'm trying to compile my Python scripts to executables using pyinstaller.
Unfortunately, the executables seem to fail to connect to Archicad.
from archicad import ACConnection
conn = ACConnection.connect()
assert conn
Traceback (most recent call last):
File "xxx", line 9, in <module>
assert conn
AssertionError
[15984] Failed to execute script 'xxx' due to unhandled exception!
There's already a similar topic but it is locked: Compile Python Scripts to Executables - Graphisoft Community
Did anyone already succeed with this? Building executables should be a common usecase for automation purposes.
Best, Wenzel
2023-11-24 01:44 PM
@wkrt-hs wrote:
I'm trying to compile my Python scripts to executables using pyinstaller.
Unfortunately, the executables seem to fail to connect to Archicad.
Dear Wenzel, you could try my script `archiconnect.py` which doesn't use the official Graphisoft archicad package, but could be used for connection testing.
Download latest archiconnect release from GitHub
Extract release and run `archiconnect.py` directly in Terminal or via Python:
./archiconnect.py
python archiconnect.py GetAllClassificationSystems
When running Archicad in background, you'll get output in Terminal:
Connecting to 127.0.0.1:19723 …
Is alive: True
Host version: Archicad 27 3001 INT
Build package:
pyinstaller -F archiconnect.py
Run packed executable:
./dist/archiconnect
If this executable does or does not work in your environment, please post a short report here so we can investigate further.
2023-12-04 03:05 PM
Hi George and thank you for your reply!
Building and running your script works fine.
But it would still be nice to also use the official archicad package for this usecase.
2023-12-05 03:49 PM
@wkrt-hs wrote:
Building and running your script works fine.
Well, this means that you have no specific PyInstaller issues when using generic requests.
@wkrt-hs wrote:
But it would still be nice to also use the official archicad package for this usecase.
If you could provide your script, I could check/rewrite it for compatibility with PyInstaller.
2023-12-05 03:59 PM
It's literally the 3 lines from the first post that already fail.
Are you able to build and run them successfully in your environment?
2023-12-05 11:56 PM
@wkrt-hs wrote:
It's literally the 3 lines from the first post that already fail.
I already have a working solution for the simple connect (see my first comment).
@wkrt-hs wrote:Are you able to build and run them successfully in your environment?
No, unfortunately, the official GS Python module doesn't work well in PyInstaller environment and I don't have enough motivation to debug and fix their code. They suppress error messages, it's not a very good practice:
@staticmethod
def find_first_port() -> int:
for port in ACConnection._port_range():
try:
ACConnection(port)
return port
except Exception:
continue
return None
@staticmethod
def find_ports(ports: slice) -> List[int]:
result = []
for port in ACConnection._port_range():
try:
ACConnection(port)
result.append(port)
except Exception:
continue
return result
I can't help you if you don't want to share your code, sorry.
2023-12-11 10:37 AM
Thanks for your response, George.
I'll see if I investigate further, but it's good to know that it's probably nothing related to my python environment.
2023-12-13 09:28 AM
@wkrt-hs wrote:
but it's good to know that it's probably nothing related to my python environment.
Sure )
Maybe GS will fix their initialisation code to be compatible with the PyInstaller environment, but I haven't found an official GitHub repo for the `archicad` Python module to create an Issue.
2024-06-15 05:23 PM
Not sure if this is relevant for @wkrt-hs anymore, but I had the same problem with pyinstaller and spent 3 days trying to find the fix.
What eventually worked for me was to collect the local archicad installation into the bundle, and to use these command-line flags with pyinstaller:
pyinstaller --collect-all archicad -F <other arguments> <python_app.py>
I hope this helps anyone who stumbles on the same topic!