gee-community / qgis-earthengine-plugin

Integrates Google Earth Engine and QGIS using Python API
http://qgis-ee-plugin.appspot.com
MIT License
454 stars 116 forks source link

AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import) #133

Open ksahbaz opened 1 year ago

ksahbaz commented 1 year ago

I've already installed the plugin and I get similar errors in two cases as follows:

Traceback (most recent call last):
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_plugin.py", line 125, in updateLayers
  import ee
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
  _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
  mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\__init__.py", line 15, in 
  from ee import batch
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
  _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
  mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\batch.py", line 18, in 
  from ee import _cloud_api_utils
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
  _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
  mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\_cloud_api_utils.py", line 25, in 
  from ee import ee_exception
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 40, in __wrapping_ee_import__
  if not _module_.data._credentials:
 AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import)
Traceback (most recent call last):
  File "C:\OSGeo4W\apps\Python39\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\__init__.py", line 15, in <module>
    from ee import batch
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\batch.py", line 18, in <module>
    from ee import _cloud_api_utils
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 38, in __wrapping_ee_import__
    _module_ = __builtin_import__(name, *args, **kwargs)
  File "C:\OSGeo4W/apps/qgis/./python\qgis\utils.py", line 888, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\OSGeo4W\apps\Python39\lib\site-packages\ee\_cloud_api_utils.py", line 25, in <module>
    from ee import ee_exception
  File "C:\Users/es/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\__init__.py", line 40, in __wrapping_ee_import__
    if not _module_.data._credentials:
AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import)

import ee works on jupyter and python in command prompt seamlessly.

QGIS: Version: 3.34.0-Prizren Code revision: ffbdd67881

Plugin: Installed version: 0.0.6

gena commented 11 months ago

Tested with 3.34.1 - the plugin seems to work fine. I'm not 100% sure, but this error may indicate that you may have conflicting Python libraries in your PATH and/or PYTHONPATH. Please make sure you don't have any so that the QGIS Python environment won't get any conflicts.

rainerwrainer commented 11 months ago

I have the same issue. I checked my PATH in the QGIS Python console with import os print(os.environ)

There are only QGIS paths in the output. Any idea how to fix it?

gena commented 11 months ago

Thanks fir reporting, investigating, trying to reproduce the problem. Maybe it's time to upgrade the EE library.

Did you just install the plugin or did it simply stop working?

wwf-simon commented 8 months ago

For me the plugin was working fine until recently. Now I am getting the same error. I'm using miniforge with a couple of environments simultaneously, but I haven't change anything in the QGIS Environment

gena commented 8 months ago

@wwf-simon, what version of the QGIS and plugin do you have installed?

wwf-simon commented 8 months ago

@gena I'm using QGIS 3.32.1 and GEE Plugin 0.0.6

arky commented 8 months ago

Does anyone figured the solution of this ?


QGIS version 3.36.0-Maidenhead
QGIS code revision [09951dc0acf](https://github.com/qgis/QGIS/commit/09951dc0acf)
Installed version   [0.0.6](file:///home/arky/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin)
``
gena commented 8 months ago

@arky, @wwf-simon, the main root cause of this problem is probably the conflict between Python versions. If there are other versions of Python installed on your machine, they may conflict with the QGIS Python. Can you check what you see then you run the following commands in QGIS Python console?

import sys
'\n'.join(sys.path)
arky commented 8 months ago

Thanks @gena I do have the multiple python versions. Any way to force qgis to use system default python or python3 would be great.

print("\n".join(sys.path))
/usr/share/qgis/python
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python/plugins
/usr/share/qgis/python/plugins
/usr/lib/python310.zip
/usr/lib/python3.10
/usr/lib/python3.10/lib-dynload
/home/arky/.local/lib/python3.10/site-packages
/usr/local/lib/python3.10/dist-packages
/usr/lib/python3/dist-packages
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python
.
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python/plugins/ee_plugin/extlibs_linux
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgis_resource_sharing
/home/arky/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgis_resource_sharing/ext_libs
gena commented 8 months ago

Hmm, it looks good, the first path is from the QGIS as well. Let me make a pre-release with the new version of Earth Engine and see if this will help. The version used in the plugin is 0.1.335 and the latest one is 0.1.395.

I've also tested it with the QGIS 3.36.1 and everything works fine at least on Windows.

gena commented 8 months ago

Can you uninstall the plugin and then install it from a zip file listed at the end of this page: https://github.com/gee-community/qgis-earthengine-plugin/actions/runs/8405368583 ?

arky commented 8 months ago

Can you uninstall the plugin and then install it from a zip file listed at the end of this page: https://github.com/gee-community/qgis-earthengine-plugin/actions/runs/8405368583 ?

Installed the new ubuntu artifact and have same data error and warning about circular dependency. So I think there might be something odd happening on my machine.

gena commented 8 months ago

Thanks, we've excluded at least one reason for the error here :-).

Are you able to call the EE from your main Python environment? Like do you have the earthengine-api package installed and can you run the earthengine authenticate command? And then also try to pip uninstall earthengine-api there to see if this is where the conflict comes from.

The plugin libs dirs are actually added at the end when the plugin is initialized, maybe adding them earlier will fix things (we can try this next).

arky commented 8 months ago

'earthengine' binary is shipped with 'earthengine-api' pip package. I have authenticated, set project name and saved the creditionals to default location.

Then tested the following in a python repl:

$ python
Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ee
>>> ee.Initialize()
>>> print(ee.String('Hello,World').getInfo())
Hello,World

Removing the earthengine-api package and then running 'import ee' in Qgis python console has the same error.

XavierCLL commented 8 months ago

Hi @arky @ksahbaz @wwf-simon @rainerwrainer

I found the issue, the problem is due to new changes in the GEE python API in the latest version, it conflicts with our custom EE import wrapper. I refactored the process of importing EE lib and the authentication method to avoid this.

Could you please do a test using the ee_plugin.zip inside the zip package by OS that you can download here in the artifacts: https://github.com/gee-community/qgis-earthengine-plugin/actions/runs/8452162046

With these changes, it requires ee.Initialize() in your scripts

wwf-simon commented 8 months ago

@XavierCLL works for me! thank you

arky commented 8 months ago

@XavierCLL Thank you for the fix.

The current "8452162046" ubuntu artifact works perfectly on Qgis 3.36.1-Maidenhead | QGIS code revision | 3e589453264

Bug resolved for me.

XavierCLL commented 7 months ago

Hi, the GitHub action for packaging has an issue fixed in a PR, so the artifact that I mentioned needs to be fixed (meanwhile my two PRs are merging), the easiest method is to open the zip, change the directory name "extlibs_linux" to "extlibs_windows" or "extlibs_darwin", zip it again and install it (Linux is not affected)

Souvansaysb commented 7 months ago

Hi all, I have an issue with EE Plugin as message below:

Traceback (most recent call last): File "C:\PROGRA~1\QGIS33~1.0\apps\Python39\lib\code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "", line 1, in File "C:\Users/rsmek/AppData/Roaming/QGIS/QGIS3\profiles\Fix_EE/python/plugins\ee_plugin__init.py", line 38, in wrapping_ee_import module = builtin_import(name, *args, **kwargs) File "C:\PROGRA~1/QGIS33~1.0/apps/qgis/./python\qgis\utils.py", line 923, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\Users\rsmek\AppData\Roaming\Python\Python39\site-packages\ee__init__.py", line 15, in from ee import _utils File "C:\Users/rsmek/AppData/Roaming/QGIS/QGIS3\profiles\Fix_EE/python/plugins\ee_plugin\init.py", line 40, in wrapping_ee_import__ if not module.data._credentials: AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import)

Souvansaysb commented 7 months ago

Could you please help me to investigate and how can I fix it?

arky commented 7 months ago

Could you please help me to investigate and how can I fix it?

@Souvansaysb Could you try with the latest version of the plugin from here? It fixed the issue for me : https://github.com/gee-community/qgis-earthengine-plugin/actions/runs/8452162046

Souvansaysb commented 7 months ago

@arky : I have tred, but I still get an error right here:

An error has occurred while executing Python code:

AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import) Traceback (most recent call last): File "C:\Users/rsmek/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\ee_plugin.py", line 125, in updateLayers import ee File "C:\Users/rsmek/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin__init.py", line 38, in wrapping_ee_import module = builtin_import__(name, *args, **kwargs) File "C:\PROGRA~1/QGIS33~1.0/apps/qgis/./python\qgis\utils.py", line 923, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\Users\rsmek\AppData\Roaming\Python\Python39\site-packages\ee__init.py", line 15, in from ee import _utils File "C:\Users/rsmek/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\ee_plugin\init.py", line 40, in wrapping_ee_import__ if not module.data._credentials: AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import)

Python version: 3.9.18 (heads/master:5eba59e, Feb 1 2024, 20:02:10) [MSC v.1929 64 bit (AMD64)] QGIS version: 3.36.0-Maidenhead Maidenhead, 09951dc0

XavierCLL commented 7 months ago

@Souvansaysb based on that code error you are not using the version that fix that, as @arky mentioned, first download this https://github.com/gee-community/qgis-earthengine-plugin/issues/133#issuecomment-2022726154 then to this https://github.com/gee-community/qgis-earthengine-plugin/issues/133#issuecomment-2041273663

Souvansaysb commented 7 months ago

@XavierCLL Thank you very much, Now my Qgis is working as normal. There are a few steps that I followed:

  1. Download this link: https://github.com/gee-community/qgis-earthengine-plugin/actions/runs/8452162046
  2. Delete profile folder
  3. Getting Qgis up to date or re-install new version
  4. Install the EE-Plugin by Zip file that you downloaded from link above.
  5. And I have edited one line of my Python script (optional)
XavierCLL commented 7 months ago

@Souvansaysb sorry for the tricks to have a functional plugin, we are going to release a new version with the fixes as soon as we can.

TaiwoGabriel commented 5 months ago

I am currently working on a time sensitive project, and I need help resolving an error from using the Python console on QGIS. I have QGIS version QGIS version 3.34.4-Prizren on my linux Ubuntu 22.04.4 LTS, Codename-Jammy. Then I successfully installed earthengine-api via my terminal, which was followed by proper authentication using earthengine authenticate.

Then I searched for Earth Engine Plugin on QGIS and I installed it. When I tried to import ee, I got the following errors below:

`Python Console

import ee Traceback (most recent call last): File "/usr/lib/python3.10/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "/home/taiwoo/.local/share/QGIS/QGIS3/profiles/default/python/ plugins/ee_plugin/init.py", line 32, in wrapping_ee_import module = builtin_import__(name, *args, **kwargs) File "/usr/lib/python3/dist-packages/qgis/utils.py", line 892, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/usr/local/lib/python3.10/dist-packages/ee/init.py", line 15, in from ee import _utils File"/home/taiwoo/.local/share/QGIS/QGIS3/profiles/default/python/ plugins/ee_plugin/init.py", line 34, in wrapping_ee_import__ if not module.data._credentials: AttributeError: partially initialized module 'ee' has no attribute 'data' (most likely due to a circular import)`

In addition, I read the thread provided here https://github.com/gee-community/qgis-earthengine-plugin/issues/133,but I could not reach a solution. I also tried the following code: export PYTHONPATH=/usr/bin/qgis/share/qgis/python and export LD_LIBRARY_PATH=/usr/bin/qgis/lib, but no hope. I still got the same error in when I tried to import ee in QGIS.

I would be glad for possible solutions to resolve this error. Thanks

XavierCLL commented 5 months ago

Hi @TaiwoGabriel, have you read this discussion thread? That error has been resolved here, follow this https://github.com/gee-community/qgis-earthengine-plugin/issues/133#issuecomment-2044517610 (and when you download that zip, decompress it and the zip inside is what you install in Qgis) the PR is still waiting to merge....

TaiwoGabriel commented 5 months ago

Thank you @XavierCLL. Your solution resolved my problem. I am really grateful. Take care.

TaiwoGabriel commented 5 months ago

Hi @XavierCLL, sorry to bother you again. I encountered an error when I tested the ee_plugin with a short code. I was able to import ee successfully. Also, from ee_plugin import Map was successful. However, when I typed the following code: countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017"), I got the error below:

Traceback (most recent call last): File "/usr/lib/python3.10/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "/usr/local/lib/python3.10/dist-packages/ee/computedobject.py", line 28, in call return type.call(cls, *args, kwargs) File "/usr/local/lib/python3.10/dist-packages/ee/_utils.py", line 38, in wrapper return func(*args, *kwargs) File "/usr/local/lib/python3.10/dist-packages/ee/deprecation.py", line 124, in Wrapper return func(args, kwargs) File "/usr/local/lib/python3.10/dist-packages/ee/featurecollection.py", line 60, in init self.initialize() File "/usr/local/lib/python3.10/dist-packages/ee/featurecollection.py", line 106, in initialize super().initialize() File "/usr/local/lib/python3.10/dist-packages/ee/collection.py", line 45, in initialize apifunction.ApiFunction.importApi(cls, cls.name(), cls.name()) File "/usr/local/lib/python3.10/dist-packages/ee/_utils.py", line 38, in wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.10/dist-packages/ee/apifunction.py", line 197, in importApi cls.initialize() File "/usr/local/lib/python3.10/dist-packages/ee/apifunction.py", line 161, in initialize signatures = data.getAlgorithms() File "/usr/local/lib/python3.10/dist-packages/ee/data.py", line 1461, in getAlgorithms _get_cloud_projects() File "/usr/local/lib/python3.10/dist-packages/ee/data.py", line 345, in _get_cloud_projects raise ee_exception.EEException( ee.ee_exception.EEException: Earth Engine client library not initialized. Run ee.Initialize()

I authenticated the earth engine client library using earthengine authenticate via my ubuntu terminal. I also switched to the python interface on terminal and then typed

import ee ee.Authenticate()- authentication successful ee.Initialize()

These three codes were executed successfully, but I still got the error above on my QGIS/Python Console when I tried this code again: countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017").

Please, can you provide any suggestion or help?

XavierCLL commented 5 months ago

the error is clear, include ee.Initialize() in your script after import ee (that is part of the second PR)

TaiwoGabriel commented 5 months ago

It worked. Thanks once again.

TaiwoGabriel commented 5 months ago

Thanks. It worked, but I got this error when I executed this code:

import ee ee.Initialize() from ee_plugin import Map countries = ee.FeatureCollection("USDOS/LSIB_SIMPLE/2017") country = countries.filter(ee.Filter.eq('country_na', 'Ukraine')) Map.addLayer(country, { 'color': 'orange' }, 'feature collection layer')

AttributeError: 'QgsRasterDataProvider' object has no attribute 'set_ee_object'. Although, the shapefile layer for Ukraine executes successfully,. What could be the reason for the error?

XavierCLL commented 5 months ago

please open a new issue because that is not related to this one and does not generate noise here, thanks!

TaiwoGabriel commented 5 months ago

Alright. Thank you.

mariochermes commented 4 months ago

@XavierCLL

The artifacts expired. Can you post them again?

XavierCLL commented 4 months ago

Hi @mariochermes, here it is the zip with the latest fixes, after install/update it, restart Qgis

ee_plugin.zip

mariochermes commented 4 months ago

Thanks @XavierCLL!