Batchfile:
I created an virtual environment (venv) for the python script. That way, everyone can compile the project even without having python installed on the machine.
@echo off
call %1\Logical\source\tools\venv\Scripts\activate.bat
python %1\Logical\source\tools\build_cam.py %1
deactivate
first I activate the venv, then I call the pyhtonscript
afterwards the venv is deactivated again
The Script reads and, if necessary, changes an “.axisfeature” File with a configured CAM Automat. If there are no changes, the file is not rewritten.
A simple “print()” within the pythonscript lets you print messages into the “Output Result” Windows in AS.
“VIRTUAL_ENV” was the absolute Path to my Project.
I tried calling the .bat in my Batchfile with the Project-Folder Parameter.
It seems to work, I copy-pasted the project to a new location and changed the path of the original one…
the compile runs through and I can see that it runs in the copied venv (by printing “sys.prefix”)
Maybe I will run into problems again if I start including specific packages into my venv…
A tips I can add to your post is that if you want to avoid virtual environnement of python you can compile your python script to executable file using “Pyinstaller” module of python.
Thanks for your explanation. We are also using python prebuild scripts.
Did you know, that you could use the logging module instead of “print()”, to create the Output Results. This is very helpful if you also like to generate “warnings” or “Errors”.
import logging
logging.basicConfig(level=logging.DEBUG)
# logging.info('message')
# logging.warning('warning')
# logging.error('error')
# EXAMPLE:
try:
# do something
except Exception as e:
logging.error(e)