I wanted to use python in GMS too and I ended up with the same error. This took me several hours to find out why and how to fix it:
TL;DR
Save the following code as start-gatan.bat
and use this start-gatan.bat
file to start GMS. The file can be placed anywhere. Note that the console window has to stay open while GMS is active!
@echo off
rem
rem File: start-gatan.bat
rem ---------------------
SET QT_PLUGIN_PATH=%ProgramData%\Miniconda3\envs\GMS_VENV_PYTHON\Library\plugins
SET gms_path=%PROGRAMFILES%\Gatan\DigitalMicrograph.exe
echo Starting GMS
echo Do not close this window!
"%gms_path%"
Important note: To show the matplotlib window you have to untick the "Execute on Background Thread"-Checkbox in the footer of the code panel! Also it takes comparatively long to execute.
Cause
This is neither a GMS error nor a python error but a Qt
error. For rendering windows matplotlib
(by default) uses PyQT
which uses Qt
. The error tells about the qwindows.dll
and that it cannot be found (explicitly?).
Side note: The renderer can be changed by adding e.g. matplotlib.use('GTK3Agg')
. This does not show up the Qt
-Error anymore but shows another error so I didn't follow this idea.
Solution
The qwindows.dll
is located in %ProgramData%/Miniconda3/envs/GMS_VENV_PYTHON/Library/plugins/platforms
. The path for the platform plugins can be set in the qt.conf
(but this didn't fix it for me which, in this thread they mention that there may be differences) or in the environment variable %QT_PLUGIN_PATH%
as I found here.
So add (create) the system variable %QT_PLUGIN_PATH%
with the value %ProgramData%\Miniconda3\envs\GMS_VENV_PYTHON\Library\plugins
. A system variable in Windows can be added under Control Panel > System > Advanced System Settings > Environment Variables.1
Note that this environment variable should only be present for GMS, not for all other QT programs. Therefore create a start-gatan.bat
and copy the code postend at the top in the TL;DR section. Now start GMS by double clicking the start-gatan.bat
and your example code will work.
Important note: To show the matplotlib window you have to untick the "Execute on Background Thread"-Checkbox in the footer of the code panel, otherwise the plot window will not be visible.
1Adding a new environment variable works but if you have one other program that uses QT (which is very likely the cause) you will run into the (nearly) same error message but in the other program. If you only have GMS pyqt
using QT this may be your solution.
Further notes
Several forum threads including the QT forum tell about duplicate paths for this qwindows.dll
. If my answer didn't help you you might want to look into that. Note that checking environment variables has to be done in the miniconda environment. So make sure to run
activate GMS_VENV_PYTHON
before outputting variables. Also you might want to have a look into the qt config which can be found at %PROGRAMDATA%/Miniconda3/envs/GMS_VENV_PYTHON/bin
. Note that there always is the file in the normal Miniconda diretory (%PROGRAMDATA%/Miniconda3/bin
) and the one in the envs
.