4

I'd like to setup PyCharm for PyQGIS 3 development. There is a good guide for PyQGIS 2, but those steps only make python 2 available, and I want to use python 3. Selecting python3 as interpreter returns an error:

Cannot setup a python SDK at python 3.6.0 (C:\OSGeo4W64\bin\python3.exe).
The SDK seems invalid

My .bat file has the following config:

SET OSGEO4W_ROOT=C:\OSGeo4W64
SET QGISNAME=qgis
SET QGIS=%OSGEO4W_ROOT%\apps\%QGISNAME%
SET QGIS_PREFIX_PATH=%QGIS%
SET PYCHARM="C:\Program Files (x86)\JetBrains\PyCharm 2016.3.2\bin\pycharm.exe"

CALL %OSGEO4W_ROOT%\bin\o4w_env.bat

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

start "PyCharm aware of QGIS" /B %PYCHARM% %*
  • 2
    Basile, I had success following Gary Sherman's excellent how-to located here: spatialgalaxy.net/2018/02/13/…. Hopefully it will help you as well. -cm – cm1 Jun 6 '18 at 19:51
4

Basile, as a P.S. to my comment, my batch file (pyqgis.cmd) looks like this:

@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass-7.4.0\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass-7.4.0\lib
path %PATH%;C:\OSGeo4W64\apps\Qt5\bin
path %PATH%;C:\OSGeo4W64\apps\Python36\Scripts

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

set QT_QPA_PLATFORM_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\Qt5\plugins\platforms
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

start "PyCharm Aware QGIS" /B "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.4\bin\pycharm64.exe" %*
REM cmd.exe /K cd /d "C:\

and my python interpreter is located here:

C:\OSGeo4W64\apps\Python36\python.exe
0

The answer above from cm1 works well with PyCharm 2018. However, with PyCharm 2019 (2019.1 and 2019.2) it won't work anymore.

See also PyCharm 2019 is not working with QGIS anymore

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.