2

I had been working with PyCharm 2019 with QGIS, and the setup was working fine,

Now I've upgraded PyCharm to 2022.2.4 Pro, and QGIS core modules are not able import.

Here is my bat file. I am using QGIS Version 3.16 and PyCharm version 2022.2.4 Pro.

@ECHO off

set OSGEO4W_ROOT="C:\Program Files\QGIS 3.16"

call "%OSGEO4W_ROOT%\bin\o4w_env.bat" call "%OSGEO4W_ROOT%\bin\qt5_env.bat" call "%OSGEO4W_ROOT%\bin\py3_env.bat"

path %OSGEO4W_ROOT%\apps\qgis\bin;%PATH% set QGIS_PREFIX_PATH=%OSGEO4W_ROOT%\apps\qgis

set GDAL_FILENAME_IS_UTF8=YES

set VSI_CACHE=TRUE set VSI_CACHE_SIZE=1000000 set QT_PLUGIN_PATH=%OSGEO4W_ROOT%\apps\qgis\qtplugins;%OSGEO4W_ROOT%\apps\qt5\plugins

SET PYCHARM="C:\Program Files\JetBrains\PyCharm 2.22.2.4\bin\pycharm64.exe"

set PYTHONPATH=%OSGEO4W_ROOT%\apps\qgis\python set PYTHONHOME=%OSGEO4W_ROOT%\apps\Python37 set PYTHONPATH=%OSGEO4W_ROOT%\apps\Python37\lib\site-packages;%PYTHONPATH%

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

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

Vince
  • 20,017
  • 15
  • 45
  • 64
VSR
  • 53
  • 4
  • No need for a custom .bat file anymore, see https://gis.stackexchange.com/a/428577/51035 – bugmenot123 Dec 12 '22 at 10:24
  • Does this answer your question? Using PyQGIS in PyCharm 2020 – bugmenot123 Dec 12 '22 at 10:24
  • pyqgs-qgis.bat file as interpreated used but still unable to import the modules – VSR Dec 12 '22 at 11:00
  • Did you wait until PyCharm was done indexing? What exactly do you mean by "unable to import the modules"? Syntax highlighting? Or launch a script from inside PyCharm? – bugmenot123 Dec 12 '22 at 11:02
  • indexing done. when imporing "from qgis.core import QgsProject" in pycharm its showing can not find the reference "QgsProject" in init.py – VSR Dec 12 '22 at 11:08
  • Hmm, I have had similar issues with the very latest PyCharm version (and a custom .bat file like yours actually). If you have the time, try a build from 2021 from https://www.jetbrains.com/pycharm/download/other.html it might just fix it. – bugmenot123 Dec 12 '22 at 12:19

0 Answers0