conda-forge / qgis-feedstock

A conda-smithy repository for qgis.
BSD 3-Clause "New" or "Revised" License
41 stars 26 forks source link

Can't use process tools from Python #429

Open wybert opened 1 month ago

wybert commented 1 month ago

Solution to issue cannot be found in the documentation.

Issue

I am trying to use the following scripts to run QGIS tools from Python. Below the scripts I run,

rom qgis.core import *

# Set the prefix path to the QGIS installation
QgsApplication.setPrefixPath("/opt/homebrew/Caskroom/miniforge/base/envs/q2/bin", True)

# Create the QgsApplication instance
qgs = QgsApplication([], False)

# Initialize the QGIS resources
qgs.initQgis()

import processing
# check all the algorithms available in QGIS
for alg in QgsApplication.processingRegistry().algorithms():
    print( "--->", alg.name())

# Finally, exit the QGIS application
qgs.exitQgis()

It prints available algorithms when I run it inside QGIS Python console.

But when I run it in the Python shell outside QGIS, it prints nothing. I checked the variables, QgsApplication.processingRegistry().algorithms() return a empty list.

Installed packages

conda list
# packages in environment at /opt/homebrew/Caskroom/miniforge/base/envs/qgis:
#
# Name                    Version                   Build  Channel
appnope                   0.1.4              pyhd8ed1ab_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
aws-c-auth                0.7.16               h51b92d1_6    conda-forge
aws-c-cal                 0.6.10               hf888d4c_1    conda-forge
aws-c-common              0.9.13               h93a5062_0    conda-forge
aws-c-compression         0.2.18               hf888d4c_1    conda-forge
aws-c-event-stream        0.4.2                h1b95c93_4    conda-forge
aws-c-http                0.8.1                heb97226_5    conda-forge
aws-c-io                  0.14.5               hb51f26e_1    conda-forge
aws-c-mqtt                0.10.2               hd37591b_4    conda-forge
aws-c-s3                  0.5.2                h09f5dbc_0    conda-forge
aws-c-sdkutils            0.1.15               hf888d4c_1    conda-forge
aws-checksums             0.1.18               hf888d4c_1    conda-forge
aws-crt-cpp               0.26.3               h06549c9_0    conda-forge
aws-sdk-cpp               1.11.267             hfbf4adc_2    conda-forge
azure-core-cpp            1.11.1               he231e37_1    conda-forge
azure-storage-blobs-cpp   12.10.0              h2ffa867_1    conda-forge
azure-storage-common-cpp  12.5.0               h09a5875_4    conda-forge
blosc                     1.21.5               hc338f07_0    conda-forge
brotli-python             1.1.0           py312h9f69965_1    conda-forge
bzip2                     1.0.8                h93a5062_5    conda-forge
c-ares                    1.28.1               h93a5062_0    conda-forge
ca-certificates           2024.2.2             hf0a4a13_0    conda-forge
cairo                     1.18.0               hd1e100b_0    conda-forge
ceres-solver              2.2.0                h036b7f2_2    conda-forge
certifi                   2024.2.2           pyhd8ed1ab_0    conda-forge
cfitsio                   4.4.0                h808cd33_1    conda-forge
charset-normalizer        3.3.2              pyhd8ed1ab_0    conda-forge
comm                      0.2.2              pyhd8ed1ab_0    conda-forge
coverage                  7.4.3           py312he37b823_1    conda-forge
curl                      8.7.1                h2d989ff_0    conda-forge
debugpy                   1.8.1           py312h20a0b95_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
draco                     1.5.7                h2ffa867_0    conda-forge
eigen                     3.4.0                h1995070_0    conda-forge
exceptiongroup            1.2.0              pyhd8ed1ab_2    conda-forge
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
exiv2                     0.28.2               h193c0af_0    conda-forge
expat                     2.6.2                hebf3989_0    conda-forge
fmt                       10.2.1               h2ffa867_0    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 h77eed37_1    conda-forge
fontconfig                2.14.2               h82840c6_0    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freetype                  2.12.1               hadb7bae_2    conda-forge
freexl                    2.0.0                hfbad9fb_0    conda-forge
future                    1.0.0              pyhd8ed1ab_0    conda-forge
gdal                      3.8.5           py312h56161e1_0    conda-forge
geos                      3.12.1               h965bd2d_0    conda-forge
geotiff                   1.7.1               h6e650f3_16    conda-forge
gettext                   0.21.1               h0186832_0    conda-forge
gflags                    2.2.2             hc88da5d_1004    conda-forge
giflib                    5.2.1                h1a8c8d9_3    conda-forge
glib                      2.80.1               h535f939_0    conda-forge
glib-tools                2.80.1               h4c882b9_0    conda-forge
glog                      0.7.0                hc6770e3_0    conda-forge
gmp                       6.3.0                h965bd2d_0    conda-forge
gsl                       2.7                  h6e638da_0    conda-forge
gst-plugins-base          1.22.9               h09b4b5e_0    conda-forge
gstreamer                 1.22.9               h551c6ff_0    conda-forge
hdf4                      4.2.15               h2ee6834_7    conda-forge
hdf5                      1.14.3          nompi_h5bb55e9_100    conda-forge
httplib2                  0.22.0             pyhd8ed1ab_0    conda-forge
icu                       73.2                 hc8870d7_0    conda-forge
idna                      3.6                pyhd8ed1ab_0    conda-forge
importlib-metadata        7.1.0              pyha770c72_0    conda-forge
importlib_metadata        7.1.0                hd8ed1ab_0    conda-forge
ipykernel                 6.29.3             pyh3cd1d5f_0    conda-forge
ipython                   8.22.2             pyh707e725_0    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
jinja2                    3.1.3              pyhd8ed1ab_0    conda-forge
json-c                    0.17                 h40ed0f5_0    conda-forge
jupyter_client            8.6.1              pyhd8ed1ab_0    conda-forge
jupyter_core              5.7.2           py312h81bd7bf_0    conda-forge
kealib                    1.5.3                h210d843_0    conda-forge
khronos-opencl-icd-loader 2023.04.17           h1a8c8d9_0    conda-forge
krb5                      1.21.2               h92f50d5_0    conda-forge
laz-perf                  3.4.0                h1995070_0    conda-forge
lcms2                     2.16                 ha0e7c42_0    conda-forge
lerc                      4.0.0                h9a09cb3_0    conda-forge
libabseil                 20240116.2      cxx17_hebf3989_0    conda-forge
libaec                    1.1.3                hebf3989_0    conda-forge
libarchive                3.7.2                hcacb583_1    conda-forge
libblas                   3.9.0           21_osxarm64_openblas    conda-forge
libboost-headers          1.84.0               hce30654_1    conda-forge
libbrotlicommon           1.1.0                hb547adb_1    conda-forge
libbrotlidec              1.1.0                hb547adb_1    conda-forge
libbrotlienc              1.1.0                hb547adb_1    conda-forge
libcblas                  3.9.0           21_osxarm64_openblas    conda-forge
libclang                  15.0.7          default_hd209bcb_4    conda-forge
libclang13                15.0.7          default_ha49e599_4    conda-forge
libcrc32c                 1.1.2                hbdafb3b_0    conda-forge
libcurl                   8.7.1                h2d989ff_0    conda-forge
libcxx                    16.0.6               h4653b0c_0    conda-forge
libdeflate                1.20                 h93a5062_0    conda-forge
libedit                   3.1.20191231         hc8eb9b7_2    conda-forge
libev                     4.33                 h93a5062_2    conda-forge
libexpat                  2.6.2                hebf3989_0    conda-forge
libffi                    3.4.2                h3422bc3_5    conda-forge
libgdal                   3.8.5                hd6f06ec_0    conda-forge
libgfortran               5.0.0           13_2_0_hd922786_3    conda-forge
libgfortran5              13.2.0               hf226fd6_3    conda-forge
libglib                   2.80.1               h535f939_0    conda-forge
libgoogle-cloud           2.22.0               hbebe991_1    conda-forge
libgoogle-cloud-storage   2.22.0               h8a76758_1    conda-forge
libgrpc                   1.62.2               h9c18a4f_0    conda-forge
libhwloc                  2.9.3           default_h4394839_1009    conda-forge
libiconv                  1.17                 h0d3ecfb_2    conda-forge
libintl                   0.22.5               h8fbad5d_2    conda-forge
libintl-devel             0.22.5               h8fbad5d_2    conda-forge
libjpeg-turbo             3.0.0                hb547adb_1    conda-forge
libkml                    1.3.0             h1eb4d9f_1018    conda-forge
liblapack                 3.9.0           21_osxarm64_openblas    conda-forge
libllvm15                 15.0.7               h2621b3d_4    conda-forge
libnetcdf                 4.9.2           nompi_h291a7c2_113    conda-forge
libnghttp2                1.58.0               ha4dd798_1    conda-forge
libogg                    1.3.4                h27ca646_1    conda-forge
libopenblas               0.3.26          openmp_h6c19121_0    conda-forge
libopus                   1.3.1                h27ca646_1    conda-forge
libpng                    1.6.43               h091b4b1_0    conda-forge
libpq                     16.2                 h0f8b458_0    conda-forge
libprotobuf               4.25.3               hbfab5d5_0    conda-forge
libre2-11                 2023.09.01           h7b2c953_2    conda-forge
librttopo                 1.1.0               hc8f776e_15    conda-forge
libsodium                 1.0.18               h27ca646_1    conda-forge
libspatialindex           1.9.3                hbdafb3b_4    conda-forge
libspatialite             5.1.0                h77c30ab_5    conda-forge
libsqlite                 3.45.3               h091b4b1_0    conda-forge
libssh2                   1.11.0               h7a5bd25_0    conda-forge
libtasn1                  4.19.0               h1a8c8d9_0    conda-forge
libtiff                   4.6.0                h07db509_3    conda-forge
libvorbis                 1.3.7                h9f76cd9_0    conda-forge
libwebp                   1.3.2                hf30222e_1    conda-forge
libwebp-base              1.3.2                hb547adb_0    conda-forge
libxml2                   2.12.6               h0d0cfa8_2    conda-forge
libxslt                   1.1.39               h223e5b9_0    conda-forge
libzip                    1.10.1               ha0bc3c6_3    conda-forge
libzlib                   1.2.13               h53f4e23_5    conda-forge
llvm-openmp               17.0.6               hcd81f8e_0    conda-forge
lxml                      5.1.0           py312h9bf3b9e_0    conda-forge
lz4-c                     1.9.4                hb7217d7_0    conda-forge
lzo                       2.10              h642e427_1000    conda-forge
markupsafe                2.1.5           py312he37b823_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
metis                     5.1.0             h13dd4ca_1007    conda-forge
minizip                   4.0.4                hc35e051_0    conda-forge
mock                      5.1.0              pyhd8ed1ab_0    conda-forge
mpfr                      4.2.1                h9546428_0    conda-forge
mysql-common              8.0.33               hf9e6398_6    conda-forge
mysql-libs                8.0.33               he3dca8b_6    conda-forge
ncurses                   6.4                  h463b476_2    conda-forge
nest-asyncio              1.6.0              pyhd8ed1ab_0    conda-forge
nitro                     2.7.dev8             h13dd4ca_0    conda-forge
nose2                     0.9.2                      py_0    conda-forge
nspr                      4.35                 hb7217d7_0    conda-forge
nss                       3.98                 h5ce2875_0    conda-forge
numpy                     1.26.4          py312h8442bc7_0    conda-forge
openjpeg                  2.5.2                h9f1df11_0    conda-forge
openssl                   3.3.0                h0d3ecfb_0    conda-forge
owslib                    0.29.3             pyhd8ed1ab_0    conda-forge
packaging                 23.2               pyhd8ed1ab_0    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
pcre2                     10.43                h26f9a81_0    conda-forge
pdal                      2.7.1                h6d00f24_1    conda-forge
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       24.0               pyhd8ed1ab_0    conda-forge
pixman                    0.43.4               hebf3989_0    conda-forge
platformdirs              4.2.1              pyhd8ed1ab_0    conda-forge
plotly                    5.19.0             pyhd8ed1ab_0    conda-forge
ply                       3.11                       py_1    conda-forge
poppler                   24.03.0              h896e6cb_0    conda-forge
poppler-data              0.4.12               hd8ed1ab_0    conda-forge
postgresql                16.2                 h1d0603d_0    conda-forge
proj                      9.4.0                h52fb9d0_1    conda-forge
prompt-toolkit            3.0.42             pyha770c72_0    conda-forge
psutil                    5.9.8           py312he37b823_0    conda-forge
psycopg2                  2.9.9           py312h84485f8_0    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.17.2             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.1              pyhd8ed1ab_0    conda-forge
pyproj                    3.6.1           py312h71aa0db_6    conda-forge
pyqt                      5.15.9          py312h550cae4_5    conda-forge
pyqt5-sip                 12.12.2         py312h9f69965_5    conda-forge
pyqtwebkit                5.15.9          py312h14105d7_2    conda-forge
pysocks                   1.7.1              pyha2e5f31_6    conda-forge
python                    3.12.2          hdf0ec26_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.12                    4_cp312    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.1           py312h02f2b3b_1    conda-forge
pyzmq                     26.0.3          py312hfa13136_0    conda-forge
qca                       2.3.8                hbd3fef1_0    conda-forge
qgis                      3.36.2          py312h0e2a93f_0    conda-forge
qjson                     0.9.0             haa19703_1009    conda-forge
qscintilla2               2.14.1          py312h14105d7_0    conda-forge
qt-main                   5.15.8              h6bf1bb6_19    conda-forge
qtkeychain                0.14.3               h4ff56cd_0    conda-forge
qtwebkit                  5.212               ha51050e_16    conda-forge
qwt                       6.2.0                haa19703_6    conda-forge
re2                       2023.09.01           h4cba328_2    conda-forge
readline                  8.2                  h92ec313_1    conda-forge
requests                  2.31.0             pyhd8ed1ab_0    conda-forge
setuptools                69.1.1             pyhd8ed1ab_0    conda-forge
sip                       6.7.12          py312h650e478_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snappy                    1.1.10               h17c5cce_0    conda-forge
spdlog                    1.12.0               he64bfa9_2    conda-forge
sqlite                    3.39.2               h40dfcc0_0    conda-forge
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
suitesparse               5.10.1               h79486c6_3    conda-forge
tbb                       2021.11.0            h2ffa867_1    conda-forge
tenacity                  8.2.3              pyhd8ed1ab_0    conda-forge
tiledb                    2.21.1               h3b251c8_0    conda-forge
tk                        8.6.13               h5083fa2_1    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tornado                   6.4             py312he37b823_0    conda-forge
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
typing_extensions         4.11.0             pyha770c72_0    conda-forge
tzcode                    2024a                h93a5062_0    conda-forge
tzdata                    2024a                h0c530f3_0    conda-forge
uriparser                 0.9.7                h13dd4ca_1    conda-forge
urllib3                   2.2.1              pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.42.0             pyhd8ed1ab_0    conda-forge
xerces-c                  3.2.5                hf393695_0    conda-forge
xz                        5.2.6                h57fd34a_0    conda-forge
yaml                      0.2.5                h3422bc3_2    conda-forge
zeromq                    4.3.5                h5119023_3    conda-forge
zipp                      3.17.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h53f4e23_5    conda-forge
zstd                      1.5.5                h4f39d0f_0    conda-forge

Environment info

conda info

     active environment : qgis
    active env location : /opt/homebrew/Caskroom/miniforge/base/envs/qgis
            shell level : 1
       user config file : /Users/kang/.condarc
 populated config files : /opt/homebrew/Caskroom/miniforge/base/.condarc
                          /Users/kang/.condarc
          conda version : 23.11.0
    conda-build version : not installed
         python version : 3.10.13.final.0
                 solver : libmamba (default)
       virtual packages : __archspec=1=m2
                          __conda=23.11.0=0
                          __osx=14.4.1=0
                          __unix=0=0
       base environment : /opt/homebrew/Caskroom/miniforge/base  (writable)
      conda av data dir : /opt/homebrew/Caskroom/miniforge/base/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/osx-arm64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /opt/homebrew/Caskroom/miniforge/base/pkgs
                          /Users/kang/.conda/pkgs
       envs directories : /opt/homebrew/Caskroom/miniforge/base/envs
                          /Users/kang/.conda/envs
               platform : osx-arm64
             user-agent : conda/23.11.0 requests/2.31.0 CPython/3.10.13 Darwin/23.4.0 OSX/14.4.1 solver/libmamba conda-libmamba-solver/23.12.0 libmambapy/1.5.5
                UID:GID : 501:20
             netrc file : None
           offline mode : False
gillins commented 1 month ago

Relevant ? https://gis.stackexchange.com/questions/321569/qgsapplication-processingregistry-loads-providers-however-is-empty-when-called @SrNetoChan do you know anything about this?