Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ksahbaz opened this issue Nov 25, 2023 · 37 comments
Assignees

Comments

@ksahbaz
Copy link

ksahbaz commented Nov 25, 2023

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

  • When I open a qgis project file
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)
  • When importing ee in QGIS Python Console.
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
Copy link
Collaborator

gena commented Dec 10, 2023

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
Copy link

rainerwrainer commented Dec 20, 2023

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
Copy link
Collaborator

gena commented Dec 21, 2023

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
Copy link

wwf-simon commented Mar 14, 2024

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
Copy link
Collaborator

gena commented Mar 16, 2024

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

@wwf-simon
Copy link

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

@arky
Copy link

arky commented Mar 23, 2024

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
Copy link
Collaborator

gena commented Mar 23, 2024

@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
Copy link

arky commented Mar 23, 2024

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
Copy link
Collaborator

gena commented Mar 23, 2024

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
Copy link
Collaborator

gena commented Mar 24, 2024

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
Copy link

arky commented Mar 24, 2024

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
Copy link
Collaborator

gena commented Mar 24, 2024

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
Copy link

arky commented Mar 24, 2024

'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.

@gena gena self-assigned this Mar 24, 2024
XavierCLL added a commit that referenced this issue Mar 27, 2024
…of EE is working perfectly for authentication process from Qgis console, also this fix a circular import bug #133
@XavierCLL
Copy link
Collaborator

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
Copy link

@XavierCLL works for me! thank you

@arky
Copy link

arky commented Mar 27, 2024

@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
Copy link
Collaborator

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
Copy link

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

Traceback (most recent call last):
File "C:\PROGRA1\QGIS331.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:\PROGRA1/QGIS331.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
Copy link

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

@arky
Copy link

arky commented Apr 8, 2024

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
Copy link

@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:\PROGRA1/QGIS331.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
Copy link
Collaborator

@Souvansaysb based on that code error you are not using the version that fix that, as @arky mentioned, first download this #133 (comment) then to this #133 (comment)

@Souvansaysb
Copy link

@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
Copy link
Collaborator

@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
Copy link

TaiwoGabriel commented Jun 24, 2024

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 #133 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
Copy link
Collaborator

Hi @TaiwoGabriel, have you read this discussion thread? That error has been resolved here, follow this #133 (comment) (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
Copy link

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

@TaiwoGabriel
Copy link

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
Copy link
Collaborator

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

@TaiwoGabriel
Copy link

It worked. Thanks once again.

@TaiwoGabriel
Copy link

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
Copy link
Collaborator

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

@TaiwoGabriel
Copy link

Alright. Thank you.

@mariochermes
Copy link

@XavierCLL

The artifacts expired. Can you post them again?

@XavierCLL
Copy link
Collaborator

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

ee_plugin.zip

@mariochermes
Copy link

Thanks @XavierCLL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants