2

I'm using Winpython 3.6.7 and I want to create a standalone application using QGIS 3.4.11. When I append the QGIS path using the sys module, nothing happens.

import sys
sys.path.append("C:\OSGeo4W64\apps\Python37\lib")
import qgis.core
>>> ModuleNotFoundError: No module named 'qgis

Previously when I wanted to work with PyQGIS 2.x (built-in Python), I created a batch file to familiarize my IDE with QGIS and set PATH and PYTHONPATH variables to QGIS \bin and \python. e.g. Something like this for Pycharm IDE:

SET OSGEO4W_ROOT=C:\OSGeo4W64
SET QGISNAME=qgis-ltr
SET QGIS=%OSGEO4W_ROOT%\apps\%QGISNAME%
SET QGIS_PREFIX_PATH=%QGIS%
SET PYCHARM="C:\Program Files\JetBrains\PyCharm Community Edition 2017.1.4\bin\pycharm64.exe"

CALL %OSGEO4W_ROOT%\bin\o4w_env.bat
CALL %OSGEO4W_ROOT%\bin\gdall6.bat

SET PATH=%PATH%;%QGIS%\bin
SET PYTHONPATH=%QGIS%\python;%PYTHONPATH%

start "PyCharm aware of QGIS" /B %PYCHARM% %*

But now that I have to use Winpython and I want to import QGIS modules to it, this doesn't work. Basically, how we can integrate different python distributions to use QGIS library while enjoying full functionality? (To add some QGIS functionalities to a previously developed standalone application, for instance)

And yes, I know it's counter-intuitive to use another Python distribution (WinPython 3.6.7) other than the Python which is shipped with QGIS. But in this case, I have to. I would be delighted to see your suggestions.

  • Thank you for the editing @TomazicM. – Afshin Salehi Sep 29 '19 at 17:57
  • For the above error: qgis.core is under %OSGEO4W%\apps\qgis-ltr\python not %OSGEO4W%\apps\Python37\lib. You want your pythonpath to point to the first. – Andreas Müller Oct 2 '19 at 11:43
  • @AndreasMüller I have already set PYTHONPATH to the first though. – Afshin Salehi Oct 2 '19 at 13:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.