0

I have a Python script that should be started via a batch file, Using Python from the QGIS installation without opening QGIS itself. Unfortunately this doesn't work because I think the Python installation of QGIS accesses the PyQt libraries differently.

What do I have to do so that the script still works via a batch via the QGIS Python installation?

The attached scripts work without any problems on another system that has Python (and PyQt) installed directly. The script without PyQt library also runs via QGIS-Python and Batch.

I use QGIS 3.16 with Python 3.7 and Windows 10 However, installing an “additional” Python version on the system is not an option.

_test.py:

#!/usr/bin/env python # -*- coding: utf-8 -*- import sys, os from PyQt5 import QtWidgets, uic from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QApplication class TEST(QtWidgets.QDialog): def __init__(self): global counter super(TEST, self).__init__() uic.loadUi(r'C:\_testdruck.ui', self) counter = 1 @pyqtSlot() def on_ButtonSchliessen_clicked(self): self.close() @pyqtSlot() def on_ButtonZeigen_clicked(self): global counter self.lineEdit_zeigen.setText(f"Wurde {str(counter)} mal gedrückt") counter += 1 def main(): app = QApplication(sys.argv) window = TEST() window.show() sys.exit(app.exec_()) if __name__ == "__main__": main() 

_test_2.py:

#!/usr/bin/env python # -*- coding: utf-8 -*- import sys, os import subprocess ergebnissdatei = open(r'C:\test.txt','w') ergebnissdatei.write("\n --> \n Das ist ein TEST!!!") ergebnissdatei.close() subprocess.Popen(r'C:\Windows\System32\notepad.exe C:\test.txt') 

and the Batchfiles:

@echo off "C:\Program Files\QGIS 3.16\apps\Python37\python.exe" "C:\_test.py" echo Beliebige Taste zum beenden pause > NUL exit @echo off "C:\Program Files\QGIS 3.16\apps\Python37\python.exe" "C:\_test_2.py" echo Beliebige Taste zum beenden pause > NUL exit 

Error running _test.cmd

Traceback (most recent call last): File "C:_test.py", line 4, in from PyQt5 import QtWidgets, uic ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden.

_testdruck.ui

<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <widget class="QPushButton" name="ButtonZeigen"> <property name="geometry"> <rect> <x>200</x> <y>230</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>Zeigen</string> </property> </widget> <widget class="QPushButton" name="ButtonSchliessen"> <property name="geometry"> <rect> <x>300</x> <y>230</y> <width>75</width> <height>23</height> </rect> </property> <property name="text"> <string>Schließen</string> </property> </widget> <widget class="QLineEdit" name="lineEdit_zeigen"> <property name="geometry"> <rect> <x>110</x> <y>150</y> <width>191</width> <height>20</height> </rect> </property> </widget> </widget> <resources/> <connections/> </ui> 

GUI

2
  • If you have QGis installed then you have python installed Commented Apr 30, 2024 at 12:11
  • I know that Python is included with the QGIS installation. That's the reason for my question. I want to run a GUI over this Python installation, without Pugin or exe. But somewhere there's something wrong with my approach. Commented Apr 30, 2024 at 12:58

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.