This is on 2023 and QGIS 3: I couldn't get import qgis
to work even though I'm not trying to re-use the installation under C:\Program Files
, but installed a processing copy via Anaconda (conda install -c conda-forge qgis
; in my case, this is Miniconda3).
Initially, I just got an ImportError
; this was under my normal Powershell environment. I then opened the Anaconda Powershell Prompt, but it didn't work in that either. Executing conda init powershell
reported that there was nothing to do. I suspected that other tweaks in my PS environment might cause problems, so I then tried the classic (cmd.exe-based) Anaconda Prompt.
It worked. I then compared the value sys.path
to the one it had under Powershell and realised that, for some reason, the path %CONDA_PREFIX%/Library/python
was missing from the latter. I ultimately fixed this by creating a .pth
file under %CONDA_PREFIX%/Lib/site-packages
and pasting the missing path into that file. That way it will automatically get appended the sys.path
every time the environment is activated, and I didn't have to mess with %PYTHONPATH%
; it's not recommended, because Anaconda does not use it and when I first tried to use it, it broke my environment.