r-spatial / RQGIS3

GNU Lesser General Public License v3.0
69 stars 19 forks source link

AttributeError #9

Closed daarizap closed 5 years ago

daarizap commented 5 years ago

Hi, I am trying to star using RQGIS3 for the first time and I have been following the instructions posted in the explanation file. After installing and opening the package the first code I have run is

find_algorithms("clip", name_only = T)

and I get this error:

Error in py_get_attr_impl(x, name, silent) : AttributeError: module 'main' has no attribute 'RQGIS3'

I am not sure what the error is about, I have been reading about it and I have found several "similar errors" and solutions but nothing has fixed the problem. Any suggestions? So far I have tried updating Rstudio, all the packages, install the packages "knitr" and "rmarkdown" and install Python 3.7. I am not very familiar with phyton but from my readings, I have the feeling the issue is related to it?

Here is the info of my session:

Rstudio V. 1.2.1335 Windows 10 V. 1803 QGIS V 3.6 Noosa

My QGIS is installed in the default folder in the C drive and R is correctly finding it.

And the full version of the code I am running:

library("raster") library("rgdal") library("RQGIS3")

library("rmarkdown") library("knitr")

find_algorithms("clip", name_only = T)

jannes-m commented 5 years ago

Usually restarting the R session helps. The error occurs if you have for example run an RQGIS command prior to an RQGIS3 command. Restarting the R session closes the Python tunnel and allows to establish a new one, e.g., a Python3 tunnel as is required by QGIS3. By contrast, QGIS2 has been using Python2. In any case, I have just updated QGIS3 to the latest version on Windows and checked that everything is working as expected.

daarizap commented 5 years ago

Thanks for the fast reply! I have restarted the session several times and also restarted the PC. But still, have the same issue. I also uninstalled RQGIS and just reinstalled RQGIS3. But the issue keeps coming. Any other suggestion that may help?

I am afraid there may be a problem with my RQGIS3 installation as the command (this I have tried in two different PCs with the same result)

vignette("install_guide", package = "RQGIS3") give the following warning Warning message: vignette ‘install_guide’ not found

jannes-m commented 5 years ago

Please uninstall QGIS and use the osgeo4w installer for installing QGIS. This should install all required dependencies. And I have to admit that I haven't updated the install_guide, will do so as time permits.

daarizap commented 5 years ago

I just reinstall QGIS through OSgeo4W with all the dependencies required, still the same error. Any other advice?

After the reinstall, the QGIS version installed was 3.4.8 long-term release.

image

jannes-m commented 5 years ago

Can you please update R and also the reticulate package? Then run:

# install latest RQGIS3 version
remotes::install_github("jannes-m/RQGIS3")
# attach RQGIS3
library("RQGIS3")
# check if the file defining the RQGIS3 python class is available
file.exists(system.file("python", "python3_funs.py", package = "RQGIS3"))  # should return TRUE
# initialize QGIS3 app, and load among others python3_funs.py
open_app()
# check if the correct Python binary was chosen
py_config()

and report the output of file.exists() and py_config().

daarizap commented 5 years ago

I have finally fixed the problem! Apparently, there was some issue with me installing the package as a user and not as administrator (the paths where the R packages are installed changes when you do it as a user or administrator). I never assumed this could be an issue as this is the first package that actually shows problems when installing in the user folder. Anyways!! It worked. (I have to say that the issue kept showing after I updated R, Rstudio and QGIS). I never got to run the commands open_app() and py_config() as the package worked after installing as administrator.