1

We developed a few standalone PyQGIS application using QGIS's libraries that come with QGIS installed program. A bit more information about our application setup. We develop using PyCharm on Windows 10 OS, and we install QGIS using its installer, not from package, for example, for this latest version, we used QGIS-OSGeo4W-3.16.11-1.msi and install into C:\OSGeo4W64 directory, then in PyCharm, we set python interpreter to C:\OSGeo4W64\apps\Python39\python.exe (the last version was pointing to Python36\python.exe), this will pull in all packages that come with the QGIS software and this has been the way we've been developing the applications. This is because from past experience (since QGIS python 2.7), we have to use all python libraries/packages that come with QGIS inside its own installation directories, because it appears that the qgis.core is built with its own versions of every package that is included in QGIS software itself. We tried in the past to point to outside PyQt libraries and couldn't get qgis.core to work in standalone application until we reference everything back into QGIS software itself.

After installing the new QGIS version 3.16 and updated the python interpreter as shown above, a lot of python commands are no longer working. To begin with, I can't even open Python Console in pycharm any more, it dies with the following code exceptions:

C:\OSGeo4W64\apps\Python39\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py" --mode=client --port=58756
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 5, in <module>
    from _pydev_comm.pydev_rpc import make_rpc_client, start_rpc_server, start_rpc_server_and_make_client
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_rpc.py", line 4, in <module>
    from _pydev_comm.pydev_server import TSingleThreadedServer
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\pydev\_pydev_comm\pydev_server.py", line 4, in <module>
    from _shaded_thriftpy.server import TServer
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\server.py", line 9, in <module>
    from _shaded_thriftpy.transport import (
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\__init__.py", line 57, in <module>
    from .sslsocket import TSSLSocket, TSSLServerSocket  # noqa
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.2\plugins\python-ce\helpers\third_party\thriftpy\_shaded_thriftpy\transport\sslsocket.py", line 7, in <module>
    import ssl
  File "C:\OSGeo4W64\apps\Python39\lib\ssl.py", line 98, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: DLL load failed while importing _ssl: The specified module could not be found.
Process finished with exit code 1

I have set the following environment variables:

PYTHONHOME C:\OSGeo4W64\apps\Python39
PYTHONPATH C:\OSGeo4W64\apps\Python39\lib;C:\OSGeo4W64\apps\Python39\DLLs;C:\OSGeo4W64\apps\qgis-ltr\python

These settings have been working with QGIS 3.6 (our last stable QGIS installation), but with this latest QGIS version, a lot of things with python are broken per dev in PyCharm.

2
  • 1
    Maybe this page can be useful: gis.stackexchange.com/questions/362874/…
    – fastest
    Commented Sep 30, 2021 at 20:54
  • @fastest thanks for the link, I think we've tried similar setup early on, I remembered that we can get it to run in PyCharm, but when we tried to package up the whole python application using PyInstaller, it couldn't get all of the packages, but maybe after all this time, this could work now, I don't know, I'll give it another try and post result here later. Commented Oct 1, 2021 at 4:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.