Python FAQ

  1. I get the following error when DigitalMicrograph®, also known as Gatan Microscopy Suite®, software starts up, what should I do?

    Answer: Most likely, when you upgraded DigitalMicrograph software from 3.4.0 to 3.4.1 or higher, you did not uninstall and reinstall Miniconda.DigitalMicrograph 3.4.0 uses an MKL-based NumPy installation.DigitalMicrograph 3.4.1 (and higher) requires an OpenBLAS-based NumPy library instead.

    To solve this problem, reinstall the DigitalMicrograph virtual environment using DigitalMicrograph 3.4.1.2984 or higher. Any version of DigitalMicrograph before 3.4.1. 2984 requires you to uninstall Miniconda before reinstalling DigitalMicrograph with Python support.

  2. How do I check what Python/NumPy version is used in DigitalMicrograph?

    Answer: On startup, you can go to the Result window / Debug.

  3. Which Python package manager should I use to install libraries on DigitalMicrograph Python Virtual environment?

    Answer: In general, we recommend using pip install instead of conda install. DigitalMicrograph uses OpenBLAS-based (NumPy) libraries, and conda install tends to install MKL-based libraries.

  4. I got this error when running a subsequent python script after using Scipy library in the first Python script, what should I do to solve this?

    Answer: Some Python libraries (such as Scipy, require the script to be run in the main thread. Running a script (that requires it to be run in the main thread) in the background thread will cause the script to hang in the DigitalMicrograph-embedded Python. To solve this, first, try to use Ctrl + Shift + Q to try to kill the script that is running in the background. If this is not successful, you may need to restart DigitalMicrograph. To run these scripts intentionally, please uncheck the checkbox Execute on Background Thread option in the bottom right Python script window the next time you run the script.

  5. Where is Miniconda installation, and where is DigitalMicrograph Python virtual environment installation?

    Answer: The global (Miniconda) python is installed under C:\ProgramData\Miniconda3\.
    DigitalMicrograph Python virtual environment is installed under C:\ProgramData\Miniconda3\envs\GMS_VENV_PYTHON.

  6. Can we run Python scripts in an external Python environment and call DigitalMicrograph for the internal functions?

    Answer: DigitalMicrograph-Python API is dependent on the DigitalMicrograph application; therefore, it is not possible to execute DigitalMicrograph functions from python outside of the DigitalMicrograph application.

  7. Why does DigitalMicrograph use Miniconda and not Anaconda?

    Answer: We chose Miniconda as a starter since it is a small package, does not take long to install, and it gives users the option to expand it when needed by using the pip install commands.

  8. Can I use some other Python software (not Miniconda)?

    Answer: Yes, however, you do need to be careful about the versions that you are using. You should make sure you are using Python version 3.7.2 and NumPy version 1.18.2. Minor changes to Python (e.g., 3.7.x) and NumPy (e.g., 1.18.x) should also work but can’t be guaranteed. The default python used is Miniconda’s DigitalMicrograph Python Virtual environment (GMS_VENV_PYTHON). You can change to use some other Python software in the Global Info dialog (File / Global Info) and restart DigitalMicrograph.

  9. Can I use my own (user-created) Python virtual environment with DigitalMicrograph?

    Answer: No, a user-created Python virtual environment is not supported, and it will not appear in the Global Info dialog / General / Scripting / Python version drop-down selection for users to select.

  10. How do I find out if OpenBLAS or MKL-based NumPy is installed in the DigitalMicrograph virtual environment?

    Answer:

    (The example shown here is an OpenBLAS based NumPy installation.)

    Launch Anaconda in administrator mode
    Activate GMS_VENV_PYTHON virtual environment :
    (base) C:\WINDOWS\system32>activate GMS_VENV_PYTHON
     
    Start python interpreter:
    (GMS_VENV_PYTHON) C:\WINDOWS\system32>python
    Python 3.7.2 (default, Feb 21 2019, 17:35:59) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import numpy as np
    >>> numpy.showConfig()
    blas_mkl_info:
      NOT AVAILABLE
    blis_info:
      NOT AVAILABLE
    openblas_info:
        library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
        libraries = ['openblas_info']
        language = f77
        define_macros = [('HAVE_CBLAS', None)]
    blas_opt_info:
        library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_info']
        libraries = ['openblas_info']
        language = f77
        define_macros = [('HAVE_CBLAS', None)]
    lapack_mkl_info:
      NOT AVAILABLE
    openblas_lapack_info:
        library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
        libraries = ['openblas_lapack_info']
        language = f77
        define_macros = [('HAVE_CBLAS', None)]
    lapack_opt_info:
        library_dirs = ['C:\\projects\\numpy-wheels\\numpy\\build\\openblas_lapack_info']
        libraries = ['openblas_lapack_info']
        language = f77
        define_macros = [('HAVE_CBLAS', None)]
  11. If I am using MKL-based libraries, how do I change to use OpenBLAS-based libraries for all packages (from Anaconda GMS_VENV_PYTHON prompt):

    Answer:
    (GMS_VENV_PYTHON) C:\WINDOWS\system32>conda install conda-forge::blas=*=openblas

    After invoking the above command, invoke “pip install XXX” where XXX is a python library.

  12. How do I use the MKL-based library for NumPy?

    Answer: You really shouldn’t, MKL-based libraries are not supported at this time. However, if you insist, you can use the following command.

    (GMS_VENV_PYTHON) C:\WINDOWS\system32>conda install numpy

    The conda package manager will update all other affected packages to use MKL-based packages.

    Note the MKL-based NumPy is not supported, and we have observed problems when invoking FFT related functions.

  13. How do I verify the conda environment is installed correctly via conda info or conda list?

    Answer: The conda list will list out all packages info that are installed in the conda environment. There should not be errors in either of these commands.

    (GMS_VENV_PYTHON) C:\WINDOWS\system32>conda info

         active environment : GMS_VENV_PYTHON
        active env location : C:\ProgramData\Miniconda3\envs\GMS_VENV_PYTHON
                shell level : 2
           user config file : C:\Users\wlei\.condarc
     populated config files :
              conda version : 4.8.3
        conda-build version : not installed
             python version : 3.7.1.final.0
           virtual packages : __cuda=9.2
           base environment : C:\ProgramData\Miniconda3  (writable)
               channel URLs : https://repo.anaconda.com/pkgs/main/win-64
                              https://repo.anaconda.com/pkgs/main/noarch
                              https://repo.anaconda.com/pkgs/r/win-64
                              https://repo.anaconda.com/pkgs/r/noarch
                              https://repo.anaconda.com/pkgs/msys2/win-64
                              https://repo.anaconda.com/pkgs/msys2/noarch
              package cache : C:\ProgramData\Miniconda3\pkgs
                              C:\Users\wlei\.conda\pkgs
                              C:\Users\wlei\AppData\Local\conda\conda\pkgs
           envs directories : C:\ProgramData\Miniconda3\envs
                              C:\Users\wlei\.conda\envs
                              C:\Users\wlei\AppData\Local\conda\conda\envs
                   platform : win-64
                 user-agent : conda/4.8.3 requests/2.21.0 CPython/3.7.1 Windows/10 Windows/10.0.18362
              administrator : True
                 netrc file : None
               offline mode : False

    (GMS_VENV_PYTHON) C:\WINDOWS\system32>conda list

    # packages in environment at C:\ProgramData\Miniconda3\envs\GMS_VENV_PYTHON:
    #
    # Name                  Version                   Build Channel
    _tflow_select          2.2.0                       eigen
    absl-py                   0.9.0                       py37_0
    asn1crypto             1.3.0                       py37_0
    astor                       0.8.1                       pypi_0    pypi
    blas                         1.0                         mkl
  14. I am using DigitalMicrograph 3.4.1. I am having some trouble installing Tensorflow 2.10. Is it supported by DigitalMicrograph 3.4.1?

    Answer: Yes, it is supported. You will need to install all the pre-requisites before pip install tensorflow command:

    The pre-requisites are: https://www.tensorflow.org/install/gpu

    CUDA Toolkit 10.2 version: https://developer.nvidia.com/cuda-downloads?target_os=Windows&target_arch=x86_64&target_version=10&target_type=exenetwork

    Visual Studio 2015-2019 x86 and x64 redistributable: https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c-redistributable-version

    Use pip install tensorflow to install the latest tensorflow (currently 2.10). 

    Sometimes, the user may see an error with the wrong h5py version, use pip uninstall h5py, and pip install h5py to install the required version.

  15. When I try to use Ctrl + Shift + Q to kill a running script, I got the following error. What should I do?

    Answer: Some operation in your script is holding onto the Python Global Interpreter Lock and not releasing it, preventing Ctrl Shift Q from terminating the script. If Ctrl + Shift + Q does not work, then you may need to restart DigitalMicrograph.