instaseis
instaseis copied to clipboard
GUI not working with conda installation
Hello, current builds of anaconda and conda installations do not work with the GUI of Instaseis. That is when using conda install -c conda-forge instaseis basemap pyqtgraph pyside2 to install Instaseis, the command python -m instaseis.gui just returns an error message.
For reference I provide part of the error message here. An explanation of the issue can be found in the next paragraph:
Traceback (most recent call last):
File "../{Anaconda-environment}/envs/testest/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "../{Anaconda-environment}/envs/testest/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "../{Anaconda-environment}/envs/testest/lib/python3.7/site-packages/instaseis/gui/__main__.py", line 6, in <module>
launch()
File "../{Anaconda-environment}/envs/testest/lib/python3.7/site-packages/instaseis/gui/instaseis_gui.py", line 930, in launch
compile_and_import_ui_files()
File "../{Anaconda-environment}/envs/testest/lib/python3.7/site-packages/instaseis/gui/instaseis_gui.py", line 79, in compile_and_import_ui_files
globals()[import_name] = imp.load_source(import_name, py_ui_file)
File "../{Anaconda-environment}/envs/testest/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 696, in _load
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 859, in get_code
File "../{Anaconda-environment}/envs/testest/lib/python3.7/imp.py", line 157, in get_data
return super().get_data(path)
File "<frozen importlib._bootstrap_external>", line 916, in get_data
FileNotFoundError: [Errno 2] No such file or directory: '../{Anaconda-environment}/envs/testest/lib/python3.7/site-packages/instaseis/gui/qt_window.py'
Specifically pyside2 does not provide the uic application in the location instaseis_gui.py expects it, it fails to compile and create a qt_window.py file and this results in the FileNotFoundError. I fixed the problem in the source code but I am new to github and do not know if I can commit (or how to go about it, I have only been using git with my private repositories on other sites).
I basically replaced the calls to use uic to compile the .ui files in instaseis_gui.py (roughly lines 60-80) with a call to pyside2-uic in the proper location (I used pyside2-uic because that is what is described in the official PySide2 documentation):
conda_env = os.getenv("CONDA_PREFIX")
conda_bin_dir = os.path.join(conda_env, "bin")
exe = os.path.join(conda_bin_dir, "pyside2-uic")
cmd = f'{exe} {ui_file} > {py_ui_file}'
This gets the specific location of pyside2-uic relative to the active conda environment. But the precise location of pyside2-uic is probably unnecessary as the binary should be in the PATH of the conda environment as well.
It is also possible to install everything except pyside2 with conda and install pyside2 with pip. For some reason this provides the uic binary in the correct location, however using pip in a such way in a conda environment is not ideal and should be avoided. This solution should work with Linux and different conda environments.
Greetings!