4

Trying to setup PyCharm Community Edition 64Bit with QGIS OSGeo4W64 installation on Windows so that I can debug some python and reference the QGIS/Qt modules.

I tried the folowing tutorials;
https://planet.qgis.org/planet/tag/pycharm/
Adding QGIS-specific Python interpreter to PyCharm on Windows?
https://silverspringenergy.com/using-pycharm-as-an-ide-for-qgis-3-plugin-development-2/

The last one creates a .bat file that is suppose to automatically open PyCharm but when it runs nothing opens, no errors either.

@echo off
call "C:\OSGEO4W64"\bin\o4w_env.bat
call "C:\OSGEO4W64"\apps\grass\grass78\etc\env.bat

@echo off
path %PATH%;C:\OSGEO4W64\apps\qgis\bin
path %PATH%;C:\OSGEO4W64\apps\grass\grass78\lib
path %PATH%;C:\OSGeo4W64\bin\apps\Qt5\bin
path %PATH%;C:\OSGeo4W64\bin\apps\Python37\Scripts
set PYTHONPATH=%PYTHONPATH%;C:\OSGeo4W64\bin\apps\qgis\python
set PYTHONHOME=C:\OSGeo4W64\bin\apps\Python37

start "PyCharm aware of Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm 
Community Edition 2019.3.1\bin\pycharm64.exe"

Could someone please help me setup the Community Edition of PyCharm with the OSGeo QGIS installation on a Windows OS?

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
MrKingsley
  • 1,443
  • 13
  • 26

1 Answers1

2

With qgis3 you'll need a different environment:

call "C:\OSGEO4W64"\bin\o4w_env.bat
call "C:\OSGEO4W64"\apps\grass\grass78\etc\env.bat

call qt5_env.bat
call py3_env.bat

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH%
set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/qgis
set GDAL_FILENAME_IS_UTF8=YES
rem Set VSI cache to be used as buffer, see #6448
set VSI_CACHE=TRUE
set VSI_CACHE_SIZE=1000000
set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins
set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python;%PYTHONPATH%

Didn't test with PyCharm, but the new environment should be the same for every IDE

Andreas Müller
  • 2,622
  • 13
  • 20
  • Seems to have done the trick, thank you! Why isn't it as easy as it is for Arc where you just point to the interpreter (i.e. C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe) or is that doing something different? – MrKingsley Jan 21 '20 at 12:30
  • 1
    the difference is, that arcgis 10.x uses an registered python where arcpy is already installed as a site-package and has no serious dependencies. Also it is a different story for arcgis pro, which uses an anaconda environment. In fact Python for QGIS3 use the same environment as QGIS itself. It is a non registered Python-Version, but has the oppertunity to write Qt-Applications or QGIS-Plugins. – Andreas Müller Jan 21 '20 at 12:42