07-02-2016, 02:02 PM (This post was last modified: 01-31-2024, 02:51 PM by Gintaras.)
These functions can be used to execute Python code in QM.
Python setup
1. Download Python 32-bit (not 64-bit) from https://www.python.org/downloads/windows/
Note: may not work with Python 3.12 and later. Works with 3.11.
2. Uninstall other versions of 32-bit Python.
3. Run the downloaded Python installer as administrator.
4. Check "Add python.exe to PATH".
5. Install.
6. Run cmd as administrator. Run it directly from explorer (eg Start menu), else it may inherit old environment variables.
7. In cmd run: where python
It should print one or more paths. One of them must be of the new installed 32-bit Python. Copy it without "\python.exe" to the clipboard.
8. In cmd change current directory to the copied. Example:
cd C:\Users\me\AppData\Local\Programs\Python\Python312-32
9. In cmd run: python -m pip install --upgrade pywin32
10. In cmd run one of the following. The first installs just what need for QM, the second something more.
python Lib\site-packages\win32comext\axscript\client\pyscript.py
python Scripts/pywin32_postinstall.py -install
11. Exit QM (not just close window). Run QM again. Now QM Python functions should work.
--
The SETUP instructions in the downloaded macro are now obsolete.
;Redirects Python print() function output to QM output.
;REMARKS ;print() will be redirected in all Python code added by PythonExec or PythonAddCode that are called after calling this function in current thread.
def Script(): ,print("test") ,print("")#empty line ,print("one\ntwo")# multiline ,print(2)# number
#--------------------------------------------------------------------------------- # Put your Python script in the Script()function. Don't need to change other code.
import sys
import ctypes
import os
import win32gui
Step 3 Download QM extension http://www.quickmacros.com/forum/attachment.php?aid=592
I want to know, in QM3, can it be called like this?
I generated the exe file, but I put the exe file together with the already installed python3.7 and it will not run on another computer.
How modify the code and I can implement the above requirements? thank you very much
03-14-2019, 06:03 AM (This post was last modified: 03-14-2019, 06:14 AM by Gintaras.)
Quote:I want to know, in QM3, can it be called like this?
I googled how Python can be used in C#. The most popular are these 2 methods: 1. Save code in a file and run the Python command line program that executes the file. 2. IronPython. But I'm sure in C# also can be used the COM method like here in QM. And probably the 4-th method - like in C. Also found "Python for .NET", not tested.
Quote:I generated the exe file, but I put the exe file together with the already installed python3.7 and it will not run on another computer.
I tested now Python 3.7.2. Works without problems.
Maybe not installed pywin32. Or installed Python 64 bit. Need 32 bit. Or did not add to PATH when installing.
I installed Python in Q:\Python37. When installing, I choose to install for all users, add to PATH, and removed the PATH length limitation. Everything else is standard.
03-14-2019, 10:39 AM (This post was last modified: 03-14-2019, 10:49 AM by win.)
Thank you for your reply, maybe I didn’t describe it clearly.
1. I installed python3.7 and pywin32 on my computer. I found that pywin32 is installed in the \Lib\site-packages\ folder of python. I tested the python script test file in QM, it can run successfully, then I Generated exe file with QM
2. I have another computer. I don't want to install python3.7 and pywin32. I want to copy the python installation folder installed on the first computer directly to the same folder as exe. Is there any way to run the exe file?
I think that Python sets the environment variable when it is installed. This is the key to success.
How to modify the Python script code in QM, set environment variables, and run exe file directly on any computer? This is very convenient, portable and easy to use.
My English is not good, I used Google Translate
The following code can't run successfully
#--------------------------------------------------------------------------------- # Put your Python script in the Script()function. Don't need to change other code.
import sys
import ctypes
import os
import win32gui
I saw Python has a version that can be redistributed with applications, but did not test it. It guess it would work only when executing the command line Python, not through COM like we do here.
I found a python version that don't need to install. Double-click Python35.cmd directly to enter python shell mode
How does QM call it directly? is it possible?
IronPython should be used directly from C#, not through PowerShell. In QM can be used C#, but without intellisense. Therefore at first test C# code in Visual Studio. Then either copy C# code to QM, or run your C# app from QM.
05-09-2019, 10:06 PM (This post was last modified: 05-10-2019, 12:17 AM by win.)
Thank you for your reply, I prefer to use powershell, because the PS syntax is simpler, don't need to install Visual Studio, the system comes with powershell ISE