I would like to work on Python script with tools from qgis in a standalone software (like Pycharm or IDLE). I am quite new with Python programming and with setting up a work environnement.
In order to create the link between Python and the qgis module, i made the Batch file like this:
@echo off
SET OSGEO4W_ROOT=C:\OSGeo4W64
call "%OSGEO4W_ROOT%"\bin\o4w_env.bat
call "%OSGEO4W_ROOT%"\apps\grass\grass76\etc\env.bat
@echo off
path %PATH%;%OSGEO4W_ROOT%\apps\qgis\bin
path %PATH%;%OSGEO4W_ROOT%\apps\grass\grass76\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 Quantum GIS" /B "C:\Program Files\JetBrains\PyCharm\bin\pycharm64.exe"
cmd.exe
After I run this file, I obtain a cmd.exe window in which I try to import qgis.core and PyQt5 to see if it works correctly:
It looks like it's working. Perfect! Then, this .batch file opens PyCharm in which I try to import qgis.core in a new script, after stting up that the Python Interpreter is the on from QGIS (direction :C:\OSGeo4W64\apps\Python37\python.exe)
But when I try to import qgis.core, I get this message:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\OSGEO4~1\apps\qgis\python\qgis\__init__.py", line 70, in <module>
from qgis.PyQt import QtCore
File "C:\Program Files\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
File "C:\OSGEO4~1\apps\qgis\python\qgis\PyQt\QtCore.py", line 24, in <module>
from PyQt5.QtCore import *
File "C:\Program Files\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'PyQt5.QtCore'
However, when I try "import PyQt5", it looks like it's working, but still importing qgis.core doesn't work and leave me with the same message.
Does anyone have an idea of how I can fix this?
I just want to be able to script tools with the qgis.core module but I'm out of ideas.