Q:

Weird Interaction between PyCharm and PyQT QFileDialog

I have written a program in Python3+QT5.  It seems to work correctly when I run it from terminal
When I run it from PyCharm, it disbehaves. 
I would use a command like  getSaveFileName() to provide a path to some local file aaa.json.  However, the path I end up getting is something like '/run/user/1000/doc/69158495/aaa.json'.  When I call the same command the second time, I get an empty string "" as a result (even though I provide a correct path).  Most weird is that my GUI halts afterwards.  It does not react to any buttons and can only be stopped from within PyCharm.  No error messages are thrown. 
When I run the code from the terminal, I can call getSaveFileName() as many times as I want, and it always returns the correct path, no halts. 
Any ideas? 
Edit: Ok, here's a super-minimal example.  When I run this code in pycharm and provide a path to a new file in my home directory, the value of the 'path' variable starts with '/run/user/1000/.....'
import sys
from PyQt5 import QtGui, QtCore, QtWidgets

app = QtWidgets. QApplication(sys.argv)
mainwindow = QtWidgets. QMainWindow()
path = QtWidgets. QFileDialog.getSaveFileName(None, "Save JSON file", "./", "JSON Files (*.json)")[0]
print(path)

A:

According to this answer, it seems that running the program from within the environment of PyCharm the "RuntimeLocation" StandardLocation is used as reference for the root path. 
Adding the DontUseNativeDialog option flag should solve the problem:
path = QtWidgets. QFileDialog.getSaveFileName(
    None, "Save JSON file", "./", "JSON Files (*.json)", 
    options=QtWidgets. QFileDialog. DontUseNativeDialog)[0]

If you want to keep using native dialogs outside the dev environment, you could eventually add some sort of --debug flag on startup, use that flag when running from PyCharm and add a check for the option before using the static functions (or, eventually, set the default option as a global variable).