1

I cannot set up the correct interpreter for PyQGIS 3 in PyCharm 2018.3.7.

Using: QGIS 3.12.0, OSGeo4W64, Python 3.7 (part of the OSGeo4W64 folder), PyCharm 2018.3.7.

My .cmd files in OSGeo4W64 look like this:

pyqgis.cmd:

SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat

@echo off path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-78\lib path %PATH%;C:\OSGeo4W64\apps\Qt5\bin path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37

set PATH=C:\Program Files\Git\bin;%PATH%

cmd.exe

pycharm.cmd:

SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat

@echo off path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-78\lib path %PATH%;C:\OSGeo4W64\apps\Qt5\bin path %PATH%;C:\OSGeo4W64\apps\Python37\Scripts

set PYTHONPATH=%PYTHONPATH%;%OSGEO4W_ROOT%\apps\qgis\python set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37

set PATH=C:\Program Files\Git\bin;%PATH%

start "PyCharm aware of QGIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.7\bin\pycharm64.exe" %*

After running pyqgis.cmd I can import different QGIS packages so everything seems ok. Running the pycharm.cmd file I can directly access PyCharm.

In PyCharm I´ve just defined the location of the new project and the path for the project interpreter which should be located in the OSGeo4W64 folder:

C:\OSGeo4W64\bin\python3.exe

interpreter location pycharm

But in the system settings the project interpreter ist still different:

intrpreter location pycharm 02

The project interpreter is not the base interpreter. After trying to add a new interpreter I onl get the pip and and setuptool python packages and to not the PyQGIS packages:

intrpreter location pycharm 02

After creating a new .py file in the project I can run some PyQGIS code (import some QGIS packages e.g.) but cannot run the code in the script window.

Maybe the SDK is missing but I didn´t get any error messages so I think this is not the issue.

Could you tell me what I´m doing wrong?

The .cmd files are based on:

Environment Setup for Plugin Development with QGIS 3

Some GIS Stack Exchange references (unfortunately haven’t brought me further):

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Mapos
  • 567
  • 4
  • 12

1 Answers1

2

Don't create a new interpreter, rather, choose Existing interpreter and select C:\OSGeo4W64\bin\python-qgis.bat

Also, I've found QGIS 3.12 buggy and I suggest rolling back to 3.10 which is the last stable release (at the time of writing this reply there is 3.14 available, but again, it is not - as of now - a long term release and I recommend not using it unless you know of a specific feature you need from it.)

Omri
  • 121
  • 6