I'm trying to use PyQGIS with Streamlit. I installed streamlit into PyQGIS build with "C:\OSGeo4W\bin\python-qgis.bat -m pip install streamlit" and solved the dependancies. I'm trying to run streamlit application with "C:\OSGeo4W\bin\python-qgis.bat -m streamlit run myapp.py".
Python-qgis.bat normally adds all the system paths etc. to load a dll file. With streamlit, however, running "from qgis.core import *" fails with the following:
ImportError: DLL load failed while importing _core: No se encontró el proceso especificado.
Traceback:
File "C:\OSGeo4W\apps\Python39\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.__dict__)
File "C:\Users\Tambet\eclipse-workspace\qgis test\strl1.py", line 27, in <module>
from qgis.core import *
File "C:\OSGeo4W\apps\qgis\python\qgis\core\__init__.py", line 25, in <module>
from qgis._core import *
I cannot find the exact information from internet, which DLL files QGIS core needs, but I found qgis_core.dll from "C:\OSGeo4W\apps\qgis\bin" and I tried to add it with the following commands:
os.environ['PYTHONPATH'] += ";C:\\OSGeo4W\\apps\\qgis\\bin"
os.add_dll_directory("C:\\OSGeo4W\\apps\\qgis\\bin")
sys.path.append("C:\\OSGeo4W\\apps\\qgis\\bin")
Under streamlit, I printed PYTHONPATH and PATH, and they are exactly the same as I get, when I run python-qgis.bat python console and ask from it about the paths (where importing from qgis.core works perfectly). So it could be somehow about the dll directories.
Which dll directories qgis.core needs and where they should be added? Has anybody any experience about using qgis with streamlit?
C:\OSGeo4W\bin\python-qgis.bat. Typeimport qgis.core. Does it throw errors?C:\OSGeo4W\bin\python-qgis.batagain. Typeimport streamlit. Does that throw errors?C:\OSGeo4W\bin\python-qgis.bat -m http.serverto check if calling python-qgis.bat with the-mswitch works in your setup. (Terminate the webserver withCtrl-Ctwice.)The interactive python shell can be closed by typing
– til_b Apr 21 '23 at 10:17exit().